我正在编写一个代码,该代码采用包含某人姓名的字符串并打印该姓名的首字母大写,每当我运行我的代码时,我都会将首字母打印两次,我不知道如何解决这个问题和得到想要的输出。
这是我的代码:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
string name = GetString();
char* pointer;
pointer = strtok(name, " ");
while (pointer != NULL)
{
printf("%c", putchar(toupper(pointer[0])));
pointer = strtok (NULL, " ");
}
printf("\n");
}
当我运行代码时,例如:ahmed salah eldin
输出:
AASSEE
我只需要 :
ASE