Cを用いてASCIIで書かれているファイルからアルファベットとスペース区切り、改行のみの文字列を読み込み、文字の組にして取り出し、出現頻度をカウントしたいと思っています。
取り出した文字の組とその出現回数をファイルに出力したのですが、一部文字化けを起こしてしまいます。
ご指摘をお願いします。
usethisfile.txt
end of the project gutenberg ebook of the lincoln country in pictures by carl frazier and rosalie frazier end of this project gutenberg ebook the lincoln country in pictures this file should be named h htm or h zip this and all associated files of various formats will be found in http www gutenberg org produced by stephen hutcheson and the online distributed proofreading team at http www pgdp net updated editions will replace the previous one the old editions will be renamed creating the works from print editions not protected by u s copyright law means that no one owns a united states copyright in these works so the foundation and you can copy and distribute it in the united states without permission and without paying copyright royalties special rules set forth in the general terms of use part of this license apply to copying and distributing project gutenberg tm electronic works to protect the project gutenberg tm concept and trademark project gutenberg is a registered trademark and may not be used if you charge for the ebooks unless you receive specific permission if you do not charge anything for copies of this ebook complying with the rules is very easy you may use this ebook for nearly any purpose such as creation of derivative works reports performances and research they may be modified and printed and given away you may do practically anything in the united states with ebooks not protected by u s copyright law redistribution is subject to the trademark license especially commercial redistribution start full license the full project gutenberg license please read this before you distribute or use this work to protect the project gutenberg tm mission of promoting the free distribution of electronic works by using or distributing this work or any other work associated in any way with the phrase project gutenberg you agree to comply with all the terms of the full project gutenberg tm license available with this file or online at www gutenberg org license section general terms of use and redistributing project gutenberg tm electronic works a by reading or using any part of this project gutenberg tm electronic work you indicate that you have read understand agree to and accept all the terms of this license and intellectual property trademark copyright agreement if you do not agree to abide by all the terms of this agreement you must cease using and return or destroy all copies of project gutenberg tm electronic works in your possession if you paid a fee for obtaining a copy of or access to a project gutenberg tm electronic work and you do not agree to be bound by the terms of this agreement you may obtain a refund from the person or entity to whom you paid the fee as set forth in paragraph
main.c
1 #include<stdio.h> 2 3 int main(void){ 4 5 FILE *fp; 6 int three[17576][4]= {{0}}, i=0, j=0; 7 char word[256]={}; 8 9 fp = fopen("usethisfile.txt", "r"); 10 11 12 while(fgets(word, 256, fp) != NULL){ 13 while(word[i] != 0x00){ 14 do{ 15 if(((three[j][0]==word[i]) && (three[j][1]==word[i+1])) && (three[j][2]==word[i+2])){ 16 three[j][3]++; 17 break; 18 } 19 else if(three[j][0]==0){ 20 three[j][0] = word[i]; 21 three[j][1] = word[i+1]; 22 three[j][2] = word[i+2]; 23 three[j][3]++; 24 break; 25 } 26 }while(three[j++][0] != 0); 27 j=0; 28 i++; 29 } 30 i=0; 31 32 } 33 34 fclose(fp); 35 fp = fopen("filethree.txt", "w"); 36 37 i=0; 38 while(three[i][0] != 0){ 39 fprintf(fp, "%c%c%c %d\n", three[i][0], three[i][1], three[i][2], three[i][3]); 40 i++; 41 } 42 fclose(fp); 43 44 return 0; 45 }
ファイル出力結果
end 2 nd 22 d o 2 of 17 of 18 f t 10 th 41 the 29 he 24 e p 6 pr 21 pro 21 roj 13 oje 13 jec 14 ect 26 ct 13 t g 10 gu 12 gut 15 ute 18 ten 15 enb 15 nbe 15 ber 15 erg 15 rg 17 g e 2 eb 5 ebo 6 boo 6 ook 6 ok 3 k o 1 e l 2 li 9 lin 4 inc 2 nco 2 col 2 oln 2 ln 2 n c 3 co 15 cou 2 oun 5 unt 2 ntr 2 try 2 ry 3 y i 2 in 12 in 11 n p 3 pi 2 pic 2 ict 2 ctu 3 tur 3 ure 2 res 3 es 12 s 9 b 3 by 7 by 8 y 1 \00 11 \00\00 15 ...
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。