linux c语言两个指针数组相互赋值的问题

linux c语言两个指针数组相互赋值的问题,第1张

你没有为指针复制,在声明char *k, *j后,应该为其显示的分配内存:

k = (char *)malloc(10 * sizeof(char))

j = (char *)malloc(10 * sizeof(char))

第一种方法数组内容自定义 #include <stdio.h> main() { int a[10],n,i scanf("%d",&n) for(i=0i<10i++)scanf("%d",&a[i]) for(i=0i<10i++)if(n==a[i])break if(i==10)printf("no found")else printf("%d",i) system("PAUSE") } 第二种方法数组内容已定义 #include <stdio.h> main() { int a[10]={0,1,2,3,4,5,6,7,8,9},n,i scanf("%d",&n) for(i=0i<10i++)if(n==a[i])break if(i==10)printf("no found")else printf("%d",i) system("PAUSE") }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7495611.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-06
下一篇 2023-04-06

发表评论

登录后才能评论

评论列表(0条)

保存