首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

奇怪的而有关问题

2012-03-04 
奇怪的而问题:#include stdio.h#include stdlib.hint main(){char *pchar a[]{h,e,l,l,o}

奇怪的而问题:
#include <stdio.h>

#include <stdlib.h>

int main()

{

 char *p;

 char a[]={'h','e','l','l','o'};

 p=a;

 while(*p!='\0')

  printf("%c",*p++);

 /*system("pause");
*/
 return 0;

}

这段代码在win-tc下正常运行.可在linux gcc下发现 hello后面还有乱码,为什么会这样?
顺便问一下,linux gcc下system("pause")不能用?

[解决办法]
因为这种初始化不会自动在后面加\0,可以这样

char a[] = "hello";
或者
char a[] = {'h','e','l','l','o',0};


另外system("pause")能不能用与gcc无关,与环境有关,system("pause")的意思就是执行pause脚本,如果你在命令行下敲入pause,能正确运行,就能用~~~~
[解决办法]
char a[]={ 'h ', 'e ', 'l ', 'l ', 'o '}; 

char a[]={ 'h ', 'e ', 'l ', 'l ', 'o ','\0'}; 

linux gcc下system("pause")不能用?
pause命令存在是可以用的,加 stdlib.h头文件

热点排行