T
totoro2468
Hi, I'm a complete NOOB.
How do I get fscanf to copy into an array? I also need to use malloc,
but where do I put it in my file?
_______________________________________________________
FILE *ifp;
char c;
int y = 0;
txtFile = (char *) malloc(FILELENGTH * sizeof(char)) ;
printf ("Enter the name of the file to analyze : ");
gets (filename);
printf ("\n");
ifp = fopen(filename, "r");
if (ifp == NULL)
{
fprintf (stderr, "Error opening file\n");
exit (-2);
}
while(fscanf (ifp, "%c", &c) != EOF)
{
txtFile[y] = c;
y++;
}
How do I get fscanf to copy into an array? I also need to use malloc,
but where do I put it in my file?
_______________________________________________________
FILE *ifp;
char c;
int y = 0;
txtFile = (char *) malloc(FILELENGTH * sizeof(char)) ;
printf ("Enter the name of the file to analyze : ");
gets (filename);
printf ("\n");
ifp = fopen(filename, "r");
if (ifp == NULL)
{
fprintf (stderr, "Error opening file\n");
exit (-2);
}
while(fscanf (ifp, "%c", &c) != EOF)
{
txtFile[y] = c;
y++;
}