The program simply reads the file count strings and their length. But the counter p of string gives me a wrong result. If I just print the count p the result will be correct but if I print the element a[i][1] (which is supposed to be p) it gives me a wrong result. For an example in element a[0][1] - it prints 12, where it is supposed to be 1.
int main(int argv,char* argc[]) {
FILE *f = fopen("d.txt","r");
int a[700000][1];
char str[120];
int i=0,l,p=0,n;
while (fgets(str,120,f)) {
l=strlen(str)-1;
p++;
a[i][0]=l;
a[i][1]=p;
i++;
}
// if I printf("%d",p); result will be correct
n=i-1;
for (i=0;i<=3;i++) {
printf("%d\n",a[i][1]); //result - 12 6 4 8
}
close(f);
return(0);
}
d.txt
No\0 one\0 is\0 here\0
result will be - 4 2 4 4