为什么用devc++编译下面的代码,运
#include
#include
int main()
{
char buf[1024],*pch;
int n1,n2;
pch = buf;
printf("The first number:");
scanf("%s",buf);
n1=strlen(pch);
printf("The second number:");
getchar();
scanf("%s",buf);
n2=strlen(pch);
printf("%d %d",n1,n2);
}
%s--是字符串pch是char型指针。
错误出在:
指针调用之前没有赋值。使用指针千万要注意这点。
因为没有赋值的指针所...全部
#include
#include
int main()
{
char buf[1024],*pch;
int n1,n2;
pch = buf;
printf("The first number:");
scanf("%s",buf);
n1=strlen(pch);
printf("The second number:");
getchar();
scanf("%s",buf);
n2=strlen(pch);
printf("%d %d",n1,n2);
}
%s--是字符串pch是char型指针。
错误出在:
指针调用之前没有赋值。使用指针千万要注意这点。
因为没有赋值的指针所指向的空间不确定。你将内容写入不确定的地址肯定出错。
顺便说句C++里的String。C里面还是别用。
有点怪怪的。
楼主加油了。收起