Hy everyone,
I would like to understand a function on strings --> strlen
Below is a code that I took from my teacher where the user inputs a string and prints out the length of the string.
Now i understand that it returns the count in "int" so my question is:Code:#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i = 0;
printf("Enter String: ");
scanf("%s", str);
while (str[i]!='\0')
{
i++;
}
printf("The String is\n%s\n", str);
printf("Length of the string: %lu\n", strlen(str));
}
Let's say i declaredat the beginning of the codeCode:int count = 0;
and then madewhy wouldn't i have the same result?Code:count = strlen(str);
Is there a way to do it also?