Okay, I have created an array str[2][100] as a test. The text file contains:
Jane
Bob
How would I copy the file into the array? I have tried using fgets:
Code:
while(fgets(ary,100,fp1) != NULL)
{
scanf("%s", str[0][0]);
}
Should I be using a different function?
Thanks.
Hey guys, I kind of figured it out. Here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1;
char filename[]="pass.txt";
char ary[100][100];
int i;
if((fp1=fopen(filename, "r")) == NULL)
{
printf("Cannot open %s for reading.", filename);
}
for(i=0;i<100;i++)
{
fscanf(fp1, "%s", ary[i]);
}
for(i=0;i<100;i++)
{
printf("%s\n", ary[i]);
}
system("PAUSE");
return 0;
}
I am using fscanf to read in the file into the array. I now need to dynamically allocate memory for the contents of the file. Going to brush up on dynamic memory allocation. Do you have an suggestions regarding which allocation method I should use to find the exact size of the text file?
Thanks.
--KiaiViper