[閒聊] C語言練習

看板mud_sanc作者 (小太保)時間14年前 (2011/08/07 12:14), 編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/1
/* test.txt ======================= adm_c laechan admin belldandy */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define file_name "test.txt" int main() { int i; char str[]="hello world!",tmp1[50],tmp2[50]; FILE *fp; // printf("hello world!\n"); // 一定要練的XD for(i=1;i<=2;i++) printf("%d.%s\n",i,str); printf("please input a word: "); scanf("%s",tmp1); printf("the word you inputed is %s.\n",tmp1); printf("please input another word: "); scanf("%s",tmp2); strcat(tmp1,tmp2); printf("tmp1+tmp2=%s.\n",tmp1); // 檔案處理 if((fp=fopen(file_name,"r"))!=NULL) { printf("the file %s is exist.\n",file_name); while(!feof(fp)) { if(fscanf(fp,"%s %s",tmp1,tmp2)==2) printf("%s is a %s\n",tmp2,tmp1); } } fclose(fp); return 1; } ===執行結果=== 1.hello world! 2.hello world! please input a word: abc the word you inputed is abc. please input another word: def tmp1+tmp2=abcdef. the file test.txt is exist. laechan is a adm_c belldandy is a admin -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.26.181.15

08/07 12:15, , 1F
下午再繼續, 今天目標是寫出一些檔案跟字串處理函數
08/07 12:15, 1F

08/07 12:15, , 2F
指標的使用是最麻煩的地方
08/07 12:15, 2F
※ 編輯: laechan 來自: 117.19.126.121 (08/08 10:00)

08/08 10:52, , 3F
C語言耶~ 好懷念~ :P
08/08 10:52, 3F

08/08 12:56, , 4F
今天練一練明天大概就可以小試一下
08/08 12:56, 4F
文章代碼(AID): #1EFX4cMe (mud_sanc)