对字符指针使用 scanf,运行时出错是为什么.(对字符数组使用scanf运行不出错)

来源:互联网 发布:如何提高网络安全意识 编辑:程序博客网 时间:2024/06/07 18:36

#include "stdafx.h"

#include<conio.h>

int _tmain(int argc, _TCHAR* argv[])

{

     char *pstr="nice to meet you!";

    

     scanf("%s",pstr);

    

     getch();

     return 0;

}


你别估计了,原因我已经找出来了.对指针赋值时,要先扩一下指针的内存在scanf之前使用pstr=(char *)malloc(50);即可头文件要有malloc.h alloc.h stblib.h 中的一个

0 0