#include <stdio.h>
int main(void)
{
char str[10];int i,length=0;
line:
{
printf("Enter string of length 10 \n");
scanf("%[A-Za-z]s", str);
}
for (i=0; str[i] != '\0'; i++)
{
length++;
}
if (length != 10)
{
printf("Length of string is : %d \n Give a string of length 10 please \n", length);
goto line;
}
else
{
printf("length = %d \n", length);
printf("Your String is: %s", str);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果用户输入长度不等于10的字符串,那么我的预期输出应为:打印输出"输入字符串长度为10"并等待用户输入另一个字符串然后检查它的长度.
我已经删除了Goto语句并检查了长度不等于10的字符串,它确实计算了长度并输出它,如下所示:
Enter string of length 10
dciciibiyciyigiy
Length of string is …Run Code Online (Sandbox Code Playgroud)