hello....i am trying to read a some integers with spaces in a file into an array, say the integers in a text file are in the shown way
1 2 3 5
13 34 2
122 2 1 34
34 23 343 53
so now i wish to read them into an integer array and print them line by line as
{1,2,3,5}
{13,34,2}
{122,2,1,34}
{34,23,343,53}
i am trying to use the code
int temp, line[128], i, j;
FILE *fp = fopen("abcd.txt","r");
if ( fp != NULL )
{
i=0;
while(!feof(fp))
{
fscanf(fp, "%d", &temp);
if(temp!='\n')
{
if(temp!=' ')
{
line[i]=temp;
}
i++;
}
else
{
line[i]='\0';
for(j=0;j=i;j++)
{
printf("%d",line[j]);
line[j]='\0';
}
printf("\n");
i=0;
}
}
}
but this isn't giving me the required result....so lemme know what corrections have to be made