- #1
anonim
- 40
- 2
- Homework Statement
- Read a file dynamically
- Relevant Equations
- -
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;
}