Hi everyone,
I am working on a c program for my intro to C class that requires me to copy 4 strings to a file and format it as a paragraph. I am struggling with writing it over however, and have been attempting to use fgets to no avail.
Currently, I just have it set to write one of the strings for testing purposes. The code compiles, but when I open the newly created file I don't see that anything was copied over. Can someone help me please? I sincerely feel like I have no idea what I'm doing.
This is my program so far:
Code:
#include <stdio.h>
int main (void)
{
FILE *fp_out;
char *str1= "Four score and seven years ago our";
char *str2= "fathers brought forth on this continent,";
char *str3= "a new nation, conceived in Liberty and dedicated";
char *str4= "to the proposition that all men are created equal.";
fp_out = fopen ("my_file", "w");
if (fp_out != NULL )
{
while (fgets (str1, sizeof(str1), fp_out) != NULL )
{
fputs (str1, fp_out);
}
fclose(fp_out);
}
else
printf("I couldn't open the file \"my_file\".\n");
return 0;
}