How can I read a text file's content and put it into an array? For example, I have 3, 2, 1, 0 in my text file and I want to read the file and store the values in an array. I am using the fscanf function to do this:
int a[4];
point = fopen("test.txt", "r");
for(int i = 0; i < 4; i++)
{
fscanf( point , "%d " , &a[i]);
}
// printing put the values ,but i dont get the text file values
for(int i = 0; i < 4; i++)
{
printf("%d\n" , a[i]);
}
I ran this program but I didn't get the values present in the text file. Can anybody please suggest a way to do this? I want to specifically solve it with the fscan function.
fopen()andfscanf()worked.