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...
Hi, (C programming) I am looking to write a program that will encrypt a text file...
Hi, (C programming) I am looking to write a program that will encrypt a text file automatically once program has opened, and have the option to decrypt it in a menu in my program. I have multiple text files that I need to encrypt, and would like if the program could encrypt all of them at once. I would also only like to decrypt the a text file once the name has been entered into a scanf function.
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt"...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt" (you will have to provide your own when debugging). The text file that is to be opened is formatted a certain way, namely, there is always one integer, one character (representing an operation), another integer, and then a new line character, with spaces between each item. A sample text file is provided below. theNumbers.txt 144 + 26 3 * 18 88 / 4 22...
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...
C Programming Number output lines of a text file as it prints to the terminal Do...
C Programming Number output lines of a text file as it prints to the terminal Do not use fgets or fopen It is possible to open file without fopen using SyS commands such as open and RDONLY Example 1 Line 1 2 Line2
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT