C语言程序设计:写一个函数,从给定的身份证号中提取出生年月日 C语言设计身份证号信息提取器:输入一身份证号后输出此人的出生...
这个简单,用以字符串str[20]={身份证号码};出生月日就是倒数第7个元素到第14个元素结束;用一个for循环,如str[20]="45032519901016127X";for(i=6;i<=13;i++) putchar(str[i]);就可以了
结果是19901016,有木有?
#include<stdio.h>
int year=0,month=0,day=0;
void getDate(char *num)
{
year=(num[6]-'0')*1000+(num[7]-'0')*100+(num[8]-'0')*10+(num[9]-'0');
month=(num[10]-'0')*10+(num[11]-'0');
day=(num[12]-'0')*10+(num[13]-'0');
}
void main()
{
char num[20]={NULL};
printf("请输入身份证号: \n");
scanf("%s",num);
getDate(num);
printf("year=%d,month=%d,day=%d",year,month,day);
}
#include <stdio.h>
#include <string.h>
void GetDate(char* str, int& year, int& month, int& day)
{
char strYear[5];
char strMonth[3];
char strDay[3];
memcpy(strYear, str + 6, 4);
memcpy(strMonth, str + 10, 2);
memcpy(strDay, str + 12, 2);
year = atoi(strYear);
month = atoi(strMonth);
day = atoi(strDay);
}
void main()
{
char str[19];
int year, month, day;
printf("身份证号:");
scanf("%s", str);
GetDate(str, year, month, day);
printf("出生年月日:%d %d %d\n", year, month, day);
}
#include
#include
void
main()
{
int
len,year,month,day;
char
str[30],str1[10];
printf("\n请输入身份证号:\n");
gets(str);
len=strlen(str);
if(len==18)
{
sscanf(str,
"%6c%4d%2d%2d",
str1,&year,&month,&day);
printf("出生日期:%d年%d月%d日\n",year,month,day);
}
else
printf("输入错误!\n");
}
#include <stdio.h>
void main()
{
int a[18];
printf("输入身份证号码:");
for(int i=0;i<18;i++)
scanf("%1d",&a[i]);
for(i=6;i<10;i++)
printf("%d",a[i]);
printf("年");
for(i=10;i<12;i++)
printf("%d",a[i]);
printf("月");
for(i=12;i<14;i++)
printf("%d",a[i]);
printf("日\n");
}
绛旓細1銆侀鍏堬紝闅忎究鍒涘缓涓涓湁main鏂规硶鐨勭被銆2銆佸畾涔変竴涓瓧绗︿覆鍙橀噺锛岃繖閲岀粰鍙橀噺璧嬪硷紝鍓嶅悗閮界暀鏈変竴涓绌烘牸銆3銆佸厛杩愯涓閬嶏紝鐪嬭緭鍑烘晥鏋滐紝鍙互鐪嬪埌鐧惧害鍖呮嫭绌烘牸鐨勫嚑涓瓧绗﹂兘鎵撳嵃鍑烘潵浜嗐4銆佷负浜嗘洿鍔犳竻鏅帮紝鐢ㄥ瓧绗︿覆瀵硅薄鍙﹀涓涓柟娉曗渓ength()鈥濆緱鍒版瀛楃涓茬殑闀垮害涓6锛 璇存槑鐨勭‘鏄滅櫨搴︹濆姞涓や釜绌烘牸鐨勯暱搴︺
绛旓細//濡傛灉鎵惧埌鍒欒繑鍥炲湪闀垮瓧绗︿覆涓殑璧峰浣嶇疆, 鑻ユ壘涓嶅埌鍒欒繑鍥-1//瑕佽繑鍥1鎴0, 鏀逛竴涓嬪氨鍙互浜唅nt find(char* source, char* target){int i,j;int s_len=strlen(source);int t_len=strlen(target);if(t_len>s_len){return -1;}for(i=0;i<=s_len-t_len;i++){j=0;int flag=1;...
绛旓細include<stdio.h>#include<string.h>int strSearch(char *str[], char *a){int find=0,i;for(i=0;i<2;i++) if(strcmp(str[i],a)==0) {find=1;break;}return find;}int main(){char *str[]={"search","abc"};printf("%d\n",strSearch(str, "abc"));return 0;} ...
绛旓細s1); //杩欓噷鐢╯trlen(s1)鍙互寰楀埌瀹為檯瀛楃涓查暱搴 scanf("%d",&m); printf("m鐨勫间负锛%d",m); copy(s1,s2,m); printf("result:%s\n",s2); return 0;}void copy(
绛旓細void change(int a,int b){int temp;temp=b;b=a;a=temp;printf("\n浜ゆ崲鍚庣殑涓や釜鏁存暟涓猴細%d %d\n",a,b);}
绛旓細浣犵浜旇瀹氫箟鐨勬暟缁 ml [4] [3] 鐨勮寖鍥存槸 ml [0~3] [0~2] 锛屽叡鏈 3 X 4 = 12 涓笺備絾浣犵殑 2 涓 for 鍑芥暟浼氫粠 ml [0] [0] 寮濮嬩竴鐩村埌 ml [5] [4] 锛岃繖閲屽凡缁忔槑鏄捐秴鍑轰簡鏁扮粍鐨勮寖鍥翠簡锛屾墍浠ラ敊璇傛纭簲璇ユ敼鎴 绗叓琛岋紝绗涓涓for(i = 0;i < 3;i++)绗崄琛岋紝绗簩...
绛旓細include<stdio.h>int fsum() { int s=0,x; while ( 1 ) { scanf("%d",&x); if ( x==-1 ) break; s+=x; } return s;}void main() { int s; s=fsum(); printf("%d\n",s);}
绛旓細绋嬪簭浠g爜濡備笅锛歩nclude <stdio.h> //缂栬瘧棰勫鐞嗗懡浠 int main(int argc, char *argv[]) //涓鍑芥暟锛瀛楃鐨勫0鏄 { char a,b; //瀹氫箟瀛楃a锛宐 scanf("%c %c",&a,&b); //杈撳叆瀛楃a锛宐 printf("%c %c\n",a,b);//鎵撳嵃瀛楃a锛宐 return 0; //杩斿洖骞朵笖杈撳嚭a锛宐 } 鎵╁睍...
绛旓細int main(){ char str[11];printf("Please enter 10 charactor: "); //杈撳叆10涓瓧绗 gets(str);sort(str, 10); //璋冪敤鎺掑簭鍑芥暟 system("pause");return 0;} //鎺掑簭鍑芥暟锛堣捣娉℃硶锛塿oid sort(char s[], int n){ for (int i=0; i<n-1; i++)for (int j=0, t; j<n-...
绛旓細include<string.h> void printit(char *str,int length) //杩斿簭杈撳嚭鍑芥暟 { int i;for(i=length-1;i>=0;i--) //浠庣粰瀹氱殑瀛楃涓茬殑鏈鍚庝竴浣嶄緷娆″悜鍓嶉亶鍘嗗悇瀛楃 putchar(*(str+i)); //姣忓悜鍓涓涓瀛楃鍗虫墦鍗拌瀛楃锛岀洿鑷崇涓涓瓧绗︿负姝倉 int main(){ char str[80]=""; ...