char username[50];
printf("[Enter Command]: \n");
scanf("%s", username);
if (strcmp("exit", username) == 0) {
exit(0);
}
if (strcmp("jobs", username) == 0) {
printf("[SERVER] No currently running jobs\n");
}
char dtm[50];
char first_word[50];
char second_word[50];
strcpy(dtm, username);
sscanf(dtm, "%s %s", first_word, second_word);
printf("%s %s\n", first_word, second_word);
我想提取输入字符串的第一个和第二个单词。我不明白为什么我的 printf() 语句会产生垃圾输出
最佳答案
将 scanf("%s", username);
替换为 gets(username);
(第 3 行)。
这就是你的问题所在。 Scanf 仅获取第一个单词。
关于c - printf() 产生垃圾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49637644/