So my code is: #include<stdio.h> But the output only returns “1” no matter how many characters I put, wha have I done incorrectly?
#include<string.h>
int main()
{
char name[25];
int length;
length = strlen(name);
printf("Enter your name.\n");
gets(name);
printf("The length of your name is %d", length);
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char name[25];
int length;
//You have not given any value to the variable name
//So, the value here is 0
//length = strlen(name);
printf("Enter your name.\n");
gets(name);
//Now your variable has a value
//So, you can calculate the length of it.
length = strlen(name);
printf("The length of your name is %d", length);
return 0;
}