Question

In: Computer Science

In C Programming Language Write a program to output to a text log file a new...

In C Programming Language

Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL".

Please screenshot the results.

Solutions

Expert Solution

//do comment if any problem arises
//code
#include <time.h>
#include <stdio.h>
#include<stdlib.h>
int main(void)
{
//current time
time_t time_now = time(NULL);
//convert to tm format using localtime function
struct tm *current_time = localtime(&time_now);
//this variable stores Day Time Date of current time
char Time[100];
//end index is returned by strftime to appen null at end
//A is current day,I is for hour, M is for minutes, p is for am or pm, x is for date
size_t end_index = strftime(Time, 100, "%A %I:%M%p %x", current_time);
//append null at end
Time[end_index] = '\0';
//open log file log.txt
FILE *log_file = fopen("log.txt", "a");
//if unable to open log file
if (log_file == NULL)
{
printf("Can't open log.txt");
exit(0);
}
//appen a newline to file
fprintf(log_file, "\n");
//write time to file
fprintf(log_file, Time);
//write successful
fprintf(log_file, " SUCCESSFUL");
return 0;
}

Output:


Related Solutions

Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
In Java language. Write a brief program that writes your name to a file in text...
In Java language. Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
Write a program, using your favourite programming language, to parse time log files to report how...
Write a program, using your favourite programming language, to parse time log files to report how much time in total spent on project. The time log file TimeLogCarbon.txt. Time Log: 2/23/12: 9:10pm - 11:40pm getting familiar with Flash 2/29/12: 12:50pm - 2:00pm getting familiar with Flash 3/1/12: 6:00pm - 11:40pm getting familiar with Flash 3/3/12: 3:00pm - 7:00pm step-debug Energy Game code 3/4/12: 8:00pm - 11:40pm start carbon game 3/5/12: 2:00pm - 3:00pm, 4:00pm - 4:30pm carbon game 3/6/12: 11:30am...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT