请问这个C代码正确吗??

来源:百度知道 编辑:UC知道 时间:2024/06/14 14:11:19
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "graphics.h"
int main()
{
int driver,mode;
char i[]="a",o[]="a";/*设定变量i为字符串变量.初始值为a*/
mima: printf("\nPlease input the password:");
scanf("%s",&i);
printf("Your password is %s\n",i);
/*设定徇环条件*/
if(i=="12")
{
driver=VGA;
mode=VGAHI;
initgraph(&driver,&mode,"C:\\JMSOFT\\DRV");
bar3d(10,10,200,200,10,10);
getch();
closegraph();
}
else
{
printf("Password is warining,please input your password agian!!\n\n");
goto mima;
}
return 0;
printf("\nPlease input your name:");
scanf("%s",&o);
printf("\n\n\n\n Welcome to my homepage!!!

scanf("%s",&i); 这里要不要加&都可以。

if(i=="12") 要用strcmp函数比较字符串

*设定徇环条件*/ 这里的文字打错了。

printf("Password is warining,please input your password agian!!\n\n"); 这里几个单词拼写错误。

return 0; 后面的语句多余了,因为永远得不到执行。可删除这3行:

printf("\nPlease input your name:");
scanf("%s",&o);
printf("\n\n\n\n Welcome to my homepage!!!%s\n\n\n",o);

使用goto是个不好的习惯,这里完全可以有替代方法。

字符串比较要用strcmp或memcmp
if(i=="12") --> if (strcmp(i, "12")==0)

scanf("%s",&i);改为scanf("%s",i);