Hello to all. I am trying to read from a file into an array. I am trying to use the first integer of the file as the size of the array.
int main(int argc, char *argv[])
{
int numberOfChar;
FILE *fp;
fp=fopen("test.txt", "rb");
if (fscanf(fp, "%d", &numberOfChar) == 1)
printf("%d\n", numberOfChar);
int x[numberOfChar];
int s;
for (s = 0; s < numberOfChar; s++)
{
fscanf(*fp, &x);
}
return 0;
}
But I get the errors:
Type error in argument 1 to 'fscanf'; found 'FILE', expected 'FILE *'.
Type error in argument 2 to 'fscanf'; found 'int *', expected 'const char *'.
both pointing to the:
fscanf(*fp, &x);
Line. Is my logic completely wrong? I thank you in advance!
int main(int argc, char *argv[])
{
int numberOfChar;
FILE *fp;
fp=fopen("test.txt", "rb");
if (fscanf(fp, "%d", &numberOfChar) == 1)
printf("%d\n", numberOfChar);
int x[numberOfChar];
int s;
for (s = 0; s < numberOfChar; s++)
{
fscanf(*fp, &x
}
return 0;
}
But I get the errors:
Type error in argument 1 to 'fscanf'; found 'FILE', expected 'FILE *'.
Type error in argument 2 to 'fscanf'; found 'int *', expected 'const char *'.
both pointing to the:
fscanf(*fp, &x
Line. Is my logic completely wrong? I thank you in advance!