int main()
{
FILE *filetext;
FILE *filecopied;
char text[50];
filetext=fopen("filetext.txt","r");
filecopied=fopen("filecopied.txt","w");
if ( (filetext==NULL) || (filecopied==NULL) )
{
printf ("A file cannot be opened");
return 1;
}
while ( fgets(text, sizeof text, filetext) )
{
char first[10];
if ( sscanf(text, "%9s", first) == 1 )
{
fprintf(filecopied, "%s\n", first);
}
}
fclose(filecopied);
fclose(filetext);
return 0;
}
Reputation Points: 2780
Solved Threads: 312
long time no c
Offline 4,790 posts
since Apr 2004