作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我删除 strtok 的 while 循环,则外部 while 循环可以继续,直到我输入 exit。但是外部的 while 循环与内部的 strtok 循环中断。我想知道为什么会发生这种情况。
#include <stdio.h>
#include <stdlib.h> // For exit() function
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <memory.h>
#include <stdlib.h>
int main()
{
char input[1024];
fgets(input,1024,stdin);
do
{
printf("%s\n",input);
char* token = strtok(input, " ");
while (token) {
printf("%s\n", token);
token = strtok(NULL, " ");
}
fgets(input,1024,stdin);
}while (strcmp(input, "exit\n") == 1);
return 0;
}
最佳答案
代替这些语句
fgets(input,1024,stdin);
}while (strcmp(input, "exit\n") == 1)
写出以下内容
}while ( fgets(input,1024,stdin) != NULL && strcmp(input, "exit\n") != 0 );
如果两个字符串不相等,函数strcmp
可以返回任何非零值。
关于c - 解决strtok While循环打破外层while循环问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60159347/
我有一组使用如下 HTML 模板的 HTML 网页,每个 HTML 页面都有不同数量的内容。所有 HTML 页面都使用相同的 CSS 文件,该文件也在下面给出。 正如我所说,每个页面的内容都不同,我希
我正在尝试以下操作。我有一个 div,其中包含一个带有大边框描边的框。这是我一直在玩的代码。 .insta{ background:#000; width:820px; height:30
所以关于 masonry.js,我遇到了一个似乎在其他任何地方都找不到的奇怪问题。 我有 the latest (3.10) version我将它包含在我的 wordpress 主题的 functio
我是一名优秀的程序员,十分优秀!