untitled

Similar documents
新・明解C言語入門編『索引』

新版 明解C言語入門編

新・解きながら学ぶC言語

移民資料

untitled

untitled

untitled

台灣經濟新報資料庫

untitled

兼營營業人營業稅額 計算辦法及申報實務

untitled

PowerPoint 簡報

C/C++ - 字符串与字符串函数

CC213

I/O Files讀寫檔案:

untitled

STANDARD

untitled

untitled

untitled

1

untitled

C 1

WTO/TBT重要通知

人身保險業務員資格測驗方案

untitled

untitled

untitled

untitled

C++ 程式設計

國立自然科學博物館館訊第263期

微處理機實習期末專題

untitled

國立陽明大學輻射防護計畫書

第三章 我國非營業特種基金制度及運作現況

依據教育部八十九年 月 日臺(八九)技(二)字第 號函

嘉義市都市計畫保護區農業區土地使用審查要點(草案)

台南縣全民學區數位學習課程進階班—PhotoImpact 10

untitled

untitled

錄 錄 參 益 金流量 陸 說 理 說 易 六 諾 說 - 2 -

九十三年第三期檔案管理工作研習營學員建議事項答覆情形彙整表

「營業稅電子資料申報繳稅作業要點」草案

untitled

untitled

新版 明解C++入門編

個人教室 / 網路硬碟

公告99年度全民健康保險醫療給付費用總額及其分配

untitled

廢證相關作業

untitled

中臺科技大學學位論文典藏

Catalan Numbers簡介

公立學校教職員成績考核辦法修正草案總說明

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2

untitled

untitled

untitled

untitled

untitled

untitled

untitled

了 立 連 立 量 領 來 例 蘭 便 不 數 不 論 更 更 更 力 更 參 例 來 例 見 量 度 量 量 參 論 量 行 量 量 瑩 理 來 錄 量 量 不 力 省 力 立 力 量 量 量 了 量 便 錄 錄 錄 料 說 省 6

九十五學年度學生團體保險契約條款

untitled

自學進修學力鑑定考試職業證照與專科學校類科及筆試科目對照表

untitled

untitled

中華民國第45屆中小學科學展覽會

untitled

untitled

派赴國外工作人員子女返國入學辦法

untitled

廉 樂 不 廉 倫 理 廉 倫 理 領 不 參 領 不 若 不 不 不 不 利 聯 行 李 聯 例 律

《摘要》

untitled

untitled

untitled

untitled

行政院國科會九十一年度專題研究

untitled

untitled

untitled

untitled

untitled

個人提供土地與建設公司合建分屋並出售合建分得之房屋,核屬營業稅法規定應課徵營業稅之範圍,自本函發布日起,經建築主管機關核發建造執照之合建分屋案件,附符合說明二之規定者外,均應辦理營業登記,課徵營業稅及營利事業所得稅

94年度學習障礙補救教學進階研習

untitled

untitled

untitled

untitled

吃寒天真的能減肥嗎

untitled

大陸黨報集團化發展之研究

untitled

國科會專題研究計畫成果報告撰寫格式說明

公務出國報告

untitled

迴授式張力控制器

untitled

Transcription:

串 串 例 : char ch= a ; char str[]= Hello ; 串 列 ch=getchar(); scanf( %c,&ch); 串 gets(str) scanf( %s,str); 8-1 數 ASCII 例 : char ch= A ; printf( %d,ch); // 65 A ascii =0x41 printf( %c,ch); // A 例 : char ch; scanf( %d,&ch); // 1, 1 數 ch=1 scanf( %c,&ch); // 1, 1 ch=0x31=49 8-2 1

#include <ctype.h> 若 不 零 若 零 isdigital 數 isupper 8-3 toupper tolower int toupper(int); int tolower(int); 8-4 2

#include <stdlib.h> 串 數 串 數 兩 ( 不 ) atoi 串 數 atof 串 數 (double) atol 串 數 ( 錄 ) strtod 串 double strtol 串 數 strtoul 串 數 8-5 串 數 (I) atoi 串 數 atof 串 數 (double) atoi( 串 ) 數 atof( 串 ) 數 8-6 3

串 數 (II) strtod 串 數 (double) strtol 串 數 strtroul strtod( 串, ) 數 strtol( 串,, ) 數 若 0 10 strtoul( 串,, ) 數 若 0 10 8-7 串 例 #include <stdio.h> #include <stdlib.h> void main(){ char str[]="1234.56=1234+.56"; char *p; printf("atoi=%d\n",atoi(str)); printf("atof=%7.2f\n",atof(str)); printf("strtod=%7.2f",strtod(str,&p)); printf(",*p='%c'\n",*p); printf("strtol=%ld",strtol(str,&p,0)); printf(",*p='%c'\n",*p); printf("strtol=%ld",strtol(str,&p,8)); printf(",*p='%c'\n",*p); } 8-8 4

數 串 數 串 sprintf sprintf printf 類 printf sprintf 串 例 : sprintf( 串 數 1, 數 2, ); int x=23.45; char str[50]; sprintf(str, x=%7.3f,x); str 串 x= 23.450 8-9 #include <stdio.h> void main(){ int x=234; float y=3.1415926535f; char str[100]; int i; 數 串 例 } sprintf(str,"%d\n",x); for (i=0;str[i]!='\0';i++) printf("%c ",str[i]); sprintf(str,"pi=%20.15f\n",y); printf("%s",str); 8-10 5

串 令 串 令 串 數 串 strcmp 串 strcpy 串連 strcat 串 串 strchr 串 度 strlen 串切 strtok 8-11 利 參數 兩數 例 #include <stdio.h> #include <stdlib.h> void main(int argc, char **argv){ double x,y; if (argc!=3){ printf("error in input\n"); exit(0); } x=atof(argv[1]); y=atof(argv[2]); printf("sum=%f\n",x+y); } 8-12 6

串 令 令 #include <string.h> 串 令 str strlen strcpy strcmp 令 mem memcpy memcmp 串 令 行 串 \0 令 數 例 char str1[]= Happy birthday ; char str2[]= Happiness ; 行 串 strcmp 不 行 memcmp 4 5 不 8-13 串 #include <string.h> 串 strcmp memcmp 串 (ASCII ) 例 : Happy < Hello < Hi > >0 = =0 < <0 8-14 7

度 串 strncmp strcmp 串 strncmp 串 數 memcmp 數 byte 數 例 char test1[]={ H, \0, a }; char test2[]={ H, \0, b }; 行 strncmp(test1,test2,3) 兩 行 memncmp(test1,test2,3) 兩 不 8-15 串 例 #include <stdio.h> #include <string.h> void main(){ char str1[]={'h','e','l','l','o','\0'}; char str2[]="happy"; char test1[]={'h','\0','a'}; char test2[]={'h','\0','b'}; if (strcmp(str1,str2)>0) printf("str1>str2\n"); if (memcmp(str1,str2,1)==0) printf("the first byte of str1 and str2 is the same\n"); 8-16 8

if (memcmp(str1,str2,2)==0) printf("the first 2 byte of str1 and str2 is the same\n"); } if (strncmp(test1,test2,3)) printf("strncmp: test1<>test2\n"); else printf("strncmp: test1==test2\n"); if (memcmp(test1,test2,3)) printf("memncmp: test<>test2\n"); else printf("memncmp: test==test2\n"); 8-17 #include <string.h> 串 串 strcpy memcpy 串 參數 ( 來 參數 ) 參數 ( 參數 ) 串 來 串 數 串 參數 參數 不 8-18 9

#include <string.h> void main(){ char s1[30],s2[30]={0}; char *p; 串 例 } strcpy(s1,"hello"); // s1[]="hello" p=strcpy(s2,s1); // s2[]="hello" memcpy(s2+2,s1,3); // s2[]="hehel" printf("s1=%s\n",s1); printf("s2=%s\n",s2); printf("address of s1=%p\n",s1); printf("address of s2=%p\n",s2); printf("pointer p=%p\n",p); 8-19 strcpy strncpy strcpy strncpy 串 strcpy 串 strncpy n 例 : char s1[]= Hello ; char s2[20]; strcpy(s2,s1); // s2 Hello strncpy(s2,s1,10); // s2 Hello strncpy(s2,s1,3); // s2 Hel 8-20 10

串連 串連 #include <string.h> strcat 串連 串參數 參數 strcat 連 串 連 說 例 : char s1[20]= ; char s2[]= ; p=strcat(s1,s2); // s1= p 串 8-21 strcat strncat strcat 來 串 連 strncat 連 來 串 n 例 char str1[30]= Data ; char str2[]= 0510 ; strcat(str1,str2); // str1= Data0510 ; strncat(str1,str2,2); // str1= Data05 ; strncat(str1,str2,10); // str1= Data0510 8-22 11

串 料 串 料 strchr 串 strstr strrchr 串 strrstr 串 char 若 料 若 不 NULL 8-23 例 : strchr char *p; char s[]= Happy new year ; p=strchr(s, a ); // p a // Happy a p=strrchr(s, a ); // p a // year a a p=strchr(s, a ); p=strchr(p+1, a ); a p=strchr(s, a ); p=strchr(p+1, a ); p=strchr(p+1, a ) 8-24 12

串 例 #include <stdio.h> #include <string.h> void main(){ char s1[]="happy new year"; char *p; printf("string s1 is at %p\n",s1); p=strchr(s1,'a'); printf("the first a is at%p\n",p); p=strchr(p+1,'a'); printf("the second a is at %p\n",p); } p=strrchr(s1,'a'); printf("the last a is at %p\n",p); 8-25 串 串 例 8-26 13

串 串 8-27 14