c语言请教,哪位高手能告诉一下错哪了谢谢了啊

来源:百度知道 编辑:UC知道 时间:2024/09/23 07:29:57
下面的程序试图有如下运行结果:which style you want to :Capital ( c ) or uncapital ( a ):c ↙COMPUTERWhich sytle you want to :Capital ( c ) or uncapital ( a ) : u↙computer请调试下面的程序,使其有如上执行结果。
#include <stdio.h>
void main(void)
{char *s; char c; printf("which style you want to :ln");printf("capital ( c ) or uncapital(a):"); c=getchar();
if(c='c') strcpy(s,"COMPUTER");
else strcpy(s,"computer"); put(s); }
先说声谢谢了啊。可是在调试上述程序时VC++6.0说遇到问题需要关闭。应该是没有问题了,可是为什么不能实现呢?我试着把*s,改为s[10],也就是把s换成数组的形式,可以实现。能给我解释一下吗?

if(c='c')-->if(c=='c')
源程序无论输什么都大写

summersuner:我觉得,s初始化与否不是决定的因素,当然它的安全性提高了。也不一定s就指向了系统区吧

#include "stdio.h"
main()
{
char *s=""; /*s要初定义*/
char c;
printf("which style you want to :ln");
printf("capital ( c ) or uncapital(a):");
c=getchar();
if(c=='c') strcpy(s,"COMPUTER");
else strcpy(s,"computer");
puts(s);

}