Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 我从哪里得到这个总线错误?_C_String_Compiler Errors - Fatal编程技术网

C 我从哪里得到这个总线错误?

C 我从哪里得到这个总线错误?,c,string,compiler-errors,C,String,Compiler Errors,当我编译这段代码时,我遇到了一个总线错误,我不明白我是怎么做的。我读到了总线错误的含义,但我仍然不太明白我的问题所在。这段代码应该重现string.h库中strcpy()函数的行为 #包括 void ft_putstr(char*str) { while(*str) 写(1,str++,1); } char*ft\u strcpy(char*dest,char*src) { 整数指数; 指数=0; while(src[index]!='\0') { dest[index]=src[index]

当我编译这段代码时,我遇到了一个总线错误,我不明白我是怎么做的。我读到了总线错误的含义,但我仍然不太明白我的问题所在。这段代码应该重现string.h库中strcpy()函数的行为

#包括
void ft_putstr(char*str)
{
while(*str)
写(1,str++,1);
}
char*ft\u strcpy(char*dest,char*src)
{
整数指数;
指数=0;
while(src[index]!='\0')
{
dest[index]=src[index];
索引++;
}
dest[索引]='\0';
返回(dest);
}
内部主(空)
{
字符*str1,*str2,*cpy;
str1=“卡梅隆”;
str2=“为什么你没有工作?”;
cpy=ft_strcpy(str1,str2);
财政司司长(cpy);
返回(0);
}
在内存中创建一个以后无法重写的字符串文本。
使用malloc和你的函数,而不是像这样初始化。

字符串文字是不可写的。没有malloc,我如何解决这个问题,我正在做的课程要求我解决这个问题而不能使用malloc。那么,使用普通数组,char数组[50];
char *name = "string";