Example
char first[100];
printf("Enter name: ");
scanf("%s", first);
printf("%zu\n", sizeof(first));
printf("%zu\n", strlen(first));
Output
Enter name: Wasi
100
4
printf("%zu\n", sizeof(first));
- prints size of the char array which is 100.
printf("%zu\n", strlen(first));
- prints the length of the input string which is 4.
Update
There is no problem in your if
condition. In the example given above, if I add the following code snippet -
for(int i = 0; i < s; i++){
if(s < 2 || s > 20){
printf("improper array size\n");
}
}
It prints the message - improper array size
100 times which is the size of the array first
.