#include <stdio.h>
#include <ctype.h>
int stringLength (char *text)
{
int count = 0;
while (*text != '\0')
{
count++;
text++;
}
return count;
}
int main()
{
char str[25];
int length;
printf("Enter key: ");
scanf("%[^\n]", str);
length = stringLength(str);
while (length > 24)
{
printf("Enter key: ");
scanf("%[^\n]", str);
length = stringLength(str);
}
printf("your string is: %s and its %d long", str, length);
return 0;
}
Cant figure out why the while loop keeps repeating. The point of the code is to just calculate the length of a string (including spaces) and give out the result.