我试图构建并运行以下程序,但它会分解执行.我想也许我犯了一个错误,但是显示了0个错误和0个警告.
在stackoverflow上研究这样的行为后,我大多看到一些错位的分号或遗忘的地址操作符,我在这个源代码中没有看到或者我忽略了什么?一些C或GCC大师可以告诉我什么是错的,为什么?
操作系统是Windows 7,编译器已启用:-pedantic -w -Wextra -Wall -ansi
这是源代码:
#include <stdio.h>
#include <string.h>
char *split(char * wort, char c)
{
int i = 0;
while (wort[i] != c && wort[i] != '\0') {
++i;
}
if (wort[i] == c) {
wort[i] = '\0';
return &wort[i+1];
} else {
return NULL;
}
}
int main()
{
char *in = "Some text here";
char *rest;
rest = split(in,' ');
if (rest == NULL) {
printf("\nString could not be devided!");
return 1;
} …Run Code Online (Sandbox Code Playgroud)