小编dim*_*ima的帖子

编译器不显示任何错误或警告但该程序不起作用

我试图构建并运行以下程序,但它会分解执行.我想也许我犯了一个错误,但是显示了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)

c gcc pointers compiler-errors compiler-warnings

1
推荐指数
1
解决办法
71
查看次数

标签 统计

c ×1

compiler-errors ×1

compiler-warnings ×1

gcc ×1

pointers ×1