Reading a string from a file - C

Status
Not open for further replies.

electroRF

Member
Hi,
Could you tell me please why this code only prints the first word of the file?

char str[50];
FILE* pFile;

pFile = fopen("myFile.txt", "r");

if (NULL != pFile)
{

fgets(pFile, str);

printf("The first word in the file is %s\n", str);

fclose(pFile);
}



---
I got additional question please.

is it possible to move files from one directory to another with C?
 
Last edited:
If you are working with DOS.. Then DOS.H has all the functions needed for file movement...
 
Thanks guys!

@misterT
you're right, it works well now.

@Ian
I'm working with windows.
Is C# needed for copying files from one folder to another?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…