1. 怎樣檢查c語言輸入數據的合法性
1、找到安裝好的C-free5,雙擊打開,進入c-free5的主界面。
2. C語言 安全的密碼 問題
寫了個命令行版本的, 使用的時候, 直接把密碼當成命令行參數使用吧,
如果不合心意, 可以自己改改(對於第4類字元, 沒有考慮符號表)
/*
@20140129
for
by'熱心網友'
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#definePASS_SAFE_NONE0
#definePASS_SAFE_LOW1
#definePASS_SAFE_MED2
#definePASS_SAFE_HIG3
intchkpasswd(char*pass);
intoutput(intsafecode);
intmain(intargc,char**argv){
if(argc!=2){
printf("UsageError ");
exit(1);
}
intret=chkpasswd(argv[1]);
output(ret);
}
intoutput(intcode){
printf("code=%d ",code);
switch(code){
casePASS_SAFE_NONE:
casePASS_SAFE_LOW:
printf("NotSafe ");
break;
casePASS_SAFE_MED:
printf("MediumSafe ");
break;
casePASS_SAFE_HIG:
printf("Safe ");
break;
}
returncode;
}
intchkpasswd(char*pass){
intlen=strlen(pass);
if(len<6)returnPASS_SAFE_NONE;
intb_class1=0;
intb_class2=0;
intb_class3=0;
intb_class4=0;
intret=0;
char*p=pass;
for(p=pass;p<(pass+len);p++){
if(ret>=PASS_SAFE_HIG)returnPASS_SAFE_HIG;
if(*p>='0'&&*p<='9'){//0-9
if(b_class1){
continue;
}else{
b_class1=1;
ret++;
}
}elseif(*p>='A'&&*p<='Z'){//Upper
if(b_class2){
continue;
}else{
b_class2=1;
ret++;
}
}elseif(*p>='a'&&*p<='z'){//Lower
if(b_class3){
continue;
}else{
b_class3=1;
ret++;
}
}else{//Symb
if(b_class4){
continue;
}else{
b_class4=1;
ret++;
}
}
}
returnret;
}
3. C語言:字元串輸入與輸出相關問題
getchar和putchar都是對字元操作的,而不是字元串,所以需要設計循環為字元串中每一個字元賦值。
以下是示例代碼,需要說明的一點是gets輸入字元串對於字元串長度沒有限制,可能導致越界溢出,不安全,建議改用fgets,另外在新的微軟標准中gets函數已被gets_s函數代替,希望對你有幫助。
include<stdio.h>intmain(){ const int count=21;
charstr1[count];charstr2[count];charch;printf("請str1輸入字元串(getchar方式): ");int i=0;while((ch=getchar())!' '){ str1[i]=ch;i+;if(i=count-1){ str1[count-1]='