【发布时间】:2016-09-24 00:08:33
【问题描述】:
当我尝试在我的 for 循环中使用“i
int main()
{
int i;
int n;
//Program to get the user's name and reply with their capitalized initials
{
//Ask user for their name
printf("What is your full name?\n");
}
//look for 1st character of each part of name given
string name = GetString();
for (i = 0; (n = strlen (name)); i < n; i++)
{
printf("Your intitals are %c", toupper(name[0]));
{
if (isspace(name[i]))
{
printf("%c", toupper(name[i+1]));
}
printf("!\n");
}
}
return 0;
}
【问题讨论】:
-
您可能只想打印一次“您的姓名缩写”消息,而不是每个用户输入的字符一次。你甚至不知道空格后面有一个字母;您最终可能会打印一个空字符,这不是一个好主意,尽管它不会造成太大的伤害。祝贺
"!\n"也应该在for循环之外。
标签: c if-statement cs50 isspace