- 論壇徽章:
- 0
|
本帖最后由 xiao09008232 于 2012-03-02 11:31 編輯
我是初學(xué)者,編了下面一段代碼:
- #include<stdio.h>
- void password(char code[17])
- {
- char c,passwd[12];
- int i=0,leap=0,j,k;
- printf("please enter your password: \n" ) ;
- while(leap==0)
- {
- leap=1;
- while((c=getchar())!='\n')
- {
- if(c>='0'&&c<='9')
- {
- passwd[i]=c;
- i++;
- }
- else
- {
- leap=0;
- }
- }
- if(i<4||i>12)
- {
- leap=0;
- }
- if(leap==1)
- {
- sprintf(code,"%02d",i--);
- for(j=0;j<=i;j++)
- {
- k=j+2;
- code[k]=passwd[j];
- }
- for(j=j+3;j<=16;j++)
- {
- code[j]='F';
- }
- }
- else
- {
- printf("WRONG PASSWORD!Please input again: \n" ) ;
- i=0;
- }
- }
- }
復(fù)制代碼 這是test.c里password函數(shù)的代碼,下面是main.c里main函數(shù)的代碼
- #include<stdio.h>
- #include"test.h"
- int main(void)
- {
- char code[17];
- password(code);
- printf("%s",code);
- }
復(fù)制代碼 還有test.h里的函數(shù)申明
- void password(char code[17]);
復(fù)制代碼 這個(gè)程序在VC++下正常運(yùn)行,結(jié)果如下:
11.jpg (6.11 KB, 下載次數(shù): 15)
下載附件
2012-03-02 11:15 上傳
在linux下也編譯通過,但結(jié)果有問題:
2.jpg (4.84 KB, 下載次數(shù): 21)
下載附件
2012-03-02 11:16 上傳
沒有輸任何值,也沒按回車,直接顯示重新輸入,怎么回事呀??? |
|