Hey
I have a file named filetext.txt with the text:
One word
Two words
Three words
Four words
and the program should read this filetext.txt and output to another file called filecopied.txt this text:
One
Two
Three
Four
I have this so far:
#include <assert.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
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;
}
// fgets(text,50,filetext);
//sscanf("%s ",text);
sscanf("%s\n",fgets(text,50,filetext));
//sscanf("%s\n",fgets(text,50,filetext));
fprintf(filecopied,"%s",text);
fclose(filecopied);
fclose(filetext);
return 0;
}
It doesnt write anything to the file so how can I solve it? Id like to use fgets, fprintf, and sscanf. Thanks.