Following is my code for reading from a file.
#include<stdio.h>
int main()
{
char s[10][10];
int i=0,j=0;
FILE *ptr=fopen("input.txt","r");
char c;
while(fscanf(ptr,"%c",&c)!=EOF)
{
if(c=='\n')
{
s[i][j]=0;
i++;
j=0;
}
else
{
s[i][j]=c;
j++;
}
}
s[i][j]=0;
fclose(ptr);
for(j=0;j<i;j++)
printf("%s\n",s[j]);
return 1;
}
and content of input.txt is
A->XAZ|Yz|z
X->xZ|x
Z->Xz
It is expected to get an output as in file.
But I'm getting an output like this .
A->XAZ|Yz|X->xZ|x
X->xZ|x
Z->Xz
Can anyone explain me that why this happens.?
`