Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing this C program (not C++) This program needs horizontal & ver

ID: 3624807 • Letter: I

Question

I need help writing this C program (not C++)
This program needs horizontal & vertical spacing

14 a

Program L14b

Write a C program what will open a sequential data file in the root directory of the current drive. Name this file myfile.txt.

Open the file in the root directory of the current drive (the current drive might not be the C: drive). The name of the file should be: myfile.txt
Be sure you verify that the file opened properly before you output data to the file.
If the file did NOT open properly, display an error message and terminate the program by dropping to the bottom of the source file.
else (the file did open properly):
Output the following three sentences (each in a line of its own) using three fprintf statements:
“My dog has fleas, but they will be gone today.”
“Every good boy does fine.”
“Frequent action causes excellence.”
Close the file.
Display a message telling the user the name of the file that the data is stored in. Be sure you add a NL at the end of your message
Exit the program

Explanation / Answer

#include #include int main() { FILE *fp; char str1[] = "My dog has fleas, but they will be gone today."; char str2[] = "Every good boy does fine."; char str3[] = "Frequent action causes excellence."; fp = fopen("myfile.txt", "w"); // fp = fopen("myfile.txt", "w"); if(fp == 0) { fprintf(stderr, "Error opening myfile.txt. "); exit(1); } fprintf(fp, "%s ", str1); fprintf(fp, "%s ", str2); fprintf(fp, "%s ", str3); printf("Data has been stored in myfile.txt "); fclose(fp); return 0; }