#include <stdio.h>
#include <stdlib.h>
struct ex
{
int i;
float j;
char *s;
};
void func (void)
{
struct ex *p = malloc(sizeof(struct ex));
p->s = malloc(20 * sizeof(char));
scanf("%s", &p->s);
printf("%s", p->s);
free(p);
}
C语言不知道问题出在哪里,代码和问题如下
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- fuill 2022-01-07 09:58关注
改了下,scanf里的&去掉了,试试看,还有加了个主函数
#include <stdio.h> #include <stdlib.h> struct ex { int i; float j; char *s; }; void func (void) { struct ex *p =malloc(sizeof(struct ex)); p->s = (char*)malloc(20 * sizeof(char)); scanf("%s", p->s); printf("%s", p->s); free(p); } int main() { func(); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
- ¥20 steam下载游戏占用内存
- ¥15 CST保存项目时失败
- ¥15 树莓派5怎么用camera module 3啊
- ¥20 java在应用程序里获取不到扬声器设备
- ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
- ¥15 Attention is all you need 的代码运行
- ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
- ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
- ¥15 前置放大电路与功率放大电路相连放大倍数出现问题