I have a C question

I know this is a C++ forum, but I was hoping someone could help me out with a C question.

I have the following code, it prints out a text file that contains:
this is a test
this is a test
etc;

but spits it out as thisisatestthisisatest, and I am trying to get it to properly output the text file as:
this is a test
this is a test

1
2
3
4
5
6
fp = fopen( "test.txt" , "r");
if (fp) {
    while (fscanf(fp, "%s", str)!=EOF)
        printf("%s",str);
    fclose(fp);
}


Any help would be very much appreciated.
Last edited on
You are not printing out any newline characters. If you add them, you can adjust your output to have newlines where you like.
Got it solved. Thank you.
In case it may be helpful to anyone else. my solutions was as follows:

FILE *fp;
char d;

fp = fopen( "test.txt" , "r");
while((d=fgetc(fp))!=EOF){
printf("%c",d);
}



Topic archived. No new replies allowed.