看板Programming
标 题请问c语言的getchar
发信站KKCITY (Fri Jun 22 21:51:09 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!news.au!zoonews.ee.ntu!news
我现在要用getchar抓取每一个输入的文字
然後再与第二次输入的字串做比对
但是,现在碰到一个问题:我要如何将getchar抓到的资料存入
p2这一个char array呢?
附上我的程式
谢谢!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 10
main() {
int i,n;
char p1[SIZE],p2[SIZE];
int c,num;
num=0;
c = getchar();
while ( c != '\n' )
{
num+=1;
if (num<=10)
{
putchar('*');
}
else
break;
}
printf("\n请确认密码:\n");
gets(p2);
if(strncmp(p1,p2,10)==0) {
printf("\n密码设定完成!\n");
printf("您输入的密码是:");
printf("%s",p1);
printf("\n");
break;
} else
printf("\n密码输入错误!\n");
}
--
┌─────◆KKCITY◆─────┐ KK免/费/拨/接 ◤
│ bbs.kkcity.com.tw │▏电话(1):449◤1999 电话(2):4058-6000
└──《From:210.208.147.227
》──┘▏帐号:kkcity 密码:kkcity
--