Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Programming Languages
C, C++ and C#
Read from a file into an array?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="fmsguy06, post: 3672713, member: 52366"] 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[s]); } 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[s]); Line. Is my logic completely wrong? I thank you in advance![/s][/s] [/QUOTE]
Verification
Post reply
Forums
Programming Languages
C, C++ and C#
Read from a file into an array?
Top