I don't understand why strlen()
is giving wrong value (ie: 9
) only for the first string. After that the values are coming correctly.
#include <stdio.h>
#include <string.h>
int main() {
int m, i, j;
i = 2;
j = 5;
char a[i][j];
for (i = 0; i <= 2; i++) {
scanf("%s", a[i]);
}
m = strlen(a[0]);
printf("%d\n", m); //here the problem is coming//
m = strlen(a[1]);
printf("%d\n", m);
m = strlen(a[2]);
printf("%d\n", m);
return 0;
}
INPUT:
heyman
jack
bro
OUTPUT:
9
4
3