Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
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
.
Forums
Homework Help
Engineering and Comp Sci Homework Help
Using Malloc to Read a File Dynamically
Reply to thread
Message
[QUOTE="anonim, post: 6346633, member: 669503"] [B]Homework Statement:[/B] Read a file dynamically [B]Relevant Equations:[/B] - [CODE=c]#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<time.h> int main(){ int index=1; int *arr; int data; char *c; FILE *fp; int input,inp; arr=(int*)malloc(sizeof(int)); fp=fopen("list2.txt","r"); input=fscanf(fp,"%d",&inp); while(input!=EOF){ printf("%d",inp); if(inp!=','){ arr[index-1]=inp; index++; arr=realloc(arr,(index)*sizeof(int)); } input=fscanf(fp,"%d",&inp); } fclose(fp); free(arr); return 0; } [/CODE]I want to read a file that file contains-> 1,2,3,5,7,888, But my code goes into loop, why? How can I fixed this? [/QUOTE]
Insert quotes…
Post reply
Forums
Homework Help
Engineering and Comp Sci Homework Help
Using Malloc to Read a File Dynamically
Back
Top