❶ 鐢╟璇瑷缂栫▼姹 18浣 韬浠借瘉镄勯獙璇佺爜
闄や简妤间笂镓璇寸殑锛屽湪琛ュ厖涓镣
1锛歝har id[19]; //链钖庝竴涓瀛楄妭鏄鐢ㄤ簬'\0'镄
2锛氶櫎浜呜繖涓铡熷洜锛岃缮链変竴涓镟撮吨瑕佺殑鏄痝ets寰楀埌镄勯兘鏄瀛楃︼纴鍦ㄤ綘镄刯isuan鍑芥暟閲岋纴for寰鐜涓
result+=((*p)*(*q));
杩椤彞璇濆叾瀹炴槸瀛楃︾殑ascII镰佺浉涔樼殑锛屽苟涓嶆槸鏁板瓧鐩镐箻锛屽彲浠ユ敼鎴
(((*p) - '0') * ((*q) - '0'));
杩欐牱灏辨槸瀵瑰簲瀛楃︾殑鏁板瓧鐩镐箻浜嗭纸杩欎釜寰埚ソ鐞呜В钖э纻锛
3锛氲槠铹秊isuan杩斿洖镄勬槸涓姣旇缉灏忕殑鏁帮纴浣嗘槸鍦╢or寰鐜閲岃$畻镄勬椂鍊檙esult瀹氢箟鎴恈har鍨嬬殑浼氭湁婧㈠嚭锛屼细瀵逛綘镄勭粨鏋沧湁褰卞搷钖э纴鎴戝缓璁鏀规垚unsigned int
❷ c璇瑷杈揿叆韬浠借瘉鍙疯緭鍑哄湴鍧镰佸嚭鐢熸棩链熼‘搴忕爜镙¢獙镰侊纻
鎴戝浗韬浠借瘉鍙风爜鐢18浣嶆暟瀛楀拰瀛楁瘝缁勬垚锛屽叾涓鍓17浣崭负韬浠借瘉鍙风殑锘烘湰淇℃伅锛屾渶钖庝竴浣崭负镙¢獙镰併傛牴鎹锲藉舵爣鍑嗭纴韬浠借瘉鍙风爜镄勫墠6浣崭负鍦板潃镰侊纴绗7鍒14浣崭负鍑虹敓镞ユ湡镰侊纴绗15鍒17浣崭负椤哄簭镰併
浠ヤ笅鏄涓涓绀轰緥浠g爜锛屽彲浠ュ疄鐜颁粠鐢ㄦ埛杈揿叆镄勮韩浠借瘉鍙蜂腑鎻愬彇鍦板潃镰併佸嚭鐢熸棩链熺爜鍜岄‘搴忕爜绛変俊鎭锛屽苟杈揿嚭鍒板睆骞曚笂锛
#include <stdio.h>
#include <string.h>
int main() {
char id[19]; // 澹版槑涓涓瀛楃︽暟缁勶纴鐢ㄤ簬瀛桦偍韬浠借瘉鍙风爜
printf("璇疯緭鍏ヨ韩浠借瘉鍙风爜锛");
scanf("%s", id); // 浠庣敤鎴疯緭鍏ヤ腑璇诲彇韬浠借瘉鍙风爜
// 鎻愬彇鍦板潃镰
char addr[7];
strncpy(addr, id, 6);
addr[6] = '\0';
// 鎻愬彇鍑虹敓镞ユ湡镰
char birth[9];
strncpy(birth, id + 6, 8);
birth[8] = '\0';
// 鎻愬彇椤哄簭镰
char order[4];
strncpy(order, id + 14, 3);
order[3] = '\0';
// 杈揿嚭缁撴灉
printf("鍦板潃镰侊细%s\n鍑虹敓镞ユ湡镰侊细%s\n椤哄簭镰侊细%s\n镙¢獙镰侊细%c\n", addr, birth, order, id[17]);
return 0;
}
鍦ㄤ笂杩颁唬镰佷腑锛屾垜浠棣栧厛澹版槑涓涓瀛楃︽暟缁刬d锛岀敤浜庡瓨鍌ㄧ敤鎴疯緭鍏ョ殑韬浠借瘉鍙风爜銆傜劧钖庝娇鐢╯canf()鍑芥暟浠庣敤鎴疯緭鍏ヤ腑璇诲彇韬浠借瘉鍙风爜銆傛帴镌锛屼娇鐢╯trncpy()鍑芥暟浠庤韩浠借瘉鍙风爜涓鎻愬彇鍦板潃镰併佸嚭鐢熸棩链熺爜鍜岄‘搴忕爜锛屽苟鍒嗗埆淇濆瓨鍒瘾ddr銆乥irth鍜宱rder鏁扮粍涓銆傛渶钖庯纴阃氲繃杈揿嚭璇鍙ュ皢缁撴灉杈揿嚭鍒板睆骞曚笂銆
闇瑕佹敞镒忕殑鏄锛岃韩浠借瘉鍙风爜镄勬渶钖庝竴浣崭负镙¢獙镰侊纴阃氩父涓嶈鐢ㄤ簬鍖哄垎韬浠借瘉鍙风爜镄勪笉钖岋纴锲犳ゅ湪涓婅堪浠g爜涓骞舵病链夊规牎楠岀爜杩涜岃В鏋愬勭悊銆