【发布时间】:2015-10-14 12:56:40
【问题描述】:
我是 C 编程的新手,我知道还有其他关于如何将字符串拆分为单词的解释,但它们似乎都与我的程序不相似。我很难在我的程序中找到错误:
#include <stdio.h>
#include <stdlib.h>
int tokenise(char str[], int start, char result[]) {
if (str[start] == "/o") {
return -1;
} else {
result = str[start];
}
}
int main() {
const int MAX_STRING = 256;
char buffer[MAX_STRING];
fgets(buffer, MAX_STRING, stdin);
char result[256];
int start;
start = tokenise(buffer, 0, result);
while ( start != -1 ) {
printf("%s\n", result);
start = tokenise(buffer, start, result);
}
}
【问题讨论】:
-
您有实际问题吗?
-
以后请使用适当的缩进;它会让你的生活更轻松,人们更有可能回答你的问题。这次我给你修好了。此外,此代码无法编译。
-
是的,我的程序无法运行,我不知道为什么
-
"是的,我的程序无法运行" 你的程序应该做什么?请提供示例输入、预期输出和实际输出。
-
我的程序应该在一行中读取,例如“hello world”,然后在单独的行中返回每个单词,例如:“hello”在一行,“world”在下一行。跨度>
标签: c