作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
运行代码后没有输出产生。空白,一无所获。问题是什么 ?
#include <stdio.h>
#include <string.h>
char* foo(){
char temp[] = "World";
char *result;
strcpy(result, temp);
return result;
}
int main(){
printf("%s", foo());
return 0;
}
最佳答案
指针result
这里没有分配任何内存。因此,您首先需要为其分配一些内存,否则,您将遇到段错误。
一种方法是使用 calloc
动态分配内存。或 malloc
这里。它位于 stdlib.h
头文件。所以,你必须包括它。然后,
char *result = malloc(strlen(temp)+1);
会做的伎俩。
关于c - 运行代码后没有输出产生。空白,一无所获。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68305485/
这是 HTML 代码: 42263 - Unencrypted Telnet Server 我正在尝试使用 Beautiful Soup 打印 42263 - Unencrypted Telnet S
我怎么知道 equal_range 没有找到任何匹配案例? 喜欢: multimap mapdic; pair::iterator,multimap::iterator> ret; // insert
我已经阅读了文档并且一直在使用该方法并取得了不同程度的成功,但我一直遇到我正在寻找的对象显然就在那里但 Range.Find 什么也不返回的情况。 test = Search_Range.Cells(
运行代码后没有输出产生。空白,一无所获。问题是什么 ? #include #include char* foo(){ char temp[] = "World"; char *re
我是一名优秀的程序员,十分优秀!