小编pav*_*van的帖子

这段代码有什么问题?

我试图模仿strtok功能,但得到分段错误.请帮帮我.

这是我的代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char argv[])
{
    int i=0;
    char c[]="get the hell out of here";
    char *p;
    char *temp=(char *)malloc(100);
    while(c[i]!='\0')
    {
        if(c[i]!=' ')
        {
            *temp=c[i];
            temp++;
            i++;
        }
        else
        {
            *temp='\0';
            printf("printing tokenn");
            puts(temp);
            i++;
            temp="";
        }
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

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

标签 统计

c ×1