一題程式設計~有難度

Having spent a lot of time typing in C programs,you have resolved to invent a specialized new kind of keyboard to aid you.(there have been a variety of attempts to improve keyboards for standard typing applications,notably the \"Dvorak keyboard\".) In your product,you plan to place the most commonly used keys for C programming in the shortest finger-travel positions. You suspect that keys such as\"*\" and \";\" are more commonly used in C programs than in English prose.However,before designing this keyboard,you need to get some hard data about the keys most commonly used in writing C source code.

Write a program that takes as input a C source code file, counts the number of occurrences of each keyboard character in the file,and writes the results to another file. Keep the count data in a one-dimesional array of integers,each element of which corresponds to the number of occurrences of one character. Recall that every character is represented by an integer character code. Assume that the possible character code range is 0~127. Write the characters found in the file and the number of times each character occurs,one entry per line.Hint :The character \'A\' can be converted to its integer character code by using the cast (int)\'A\',and the ASCII character code 65 can be converted to its character equivalent(\'A\')by using the cast (char)65.

----------------------------------------------------------------------

大家一起來幫我想吧 : )

Update:

我是沒有很仔細看拉~~我看這題目又臭又長~我就照著po拉~是用C語言來寫......希望可以把程式碼po出來給我看~QQ

1 Answer

Rating
  • 2 decades ago
    Favorite Answer

    這題目沒有說要用的語言,總之就是輸一個.c,然後記錄每個字元出現的次數。

    有難度?

    你希望大家幫你想什麼?

    2006-05-20 20:49:17 補充:

    #include <stdio.h>int main(int argc, char** argv){ if(argc != 2) { printf("usage:%s [input.c]\n", argv[0]); return -1; } FILE* fp = fopen(argv[1], "rt"); int c, count[127] = {0}; while((c = fgetc(fp)) != EOF) { count[c]++; } fclose(fp);

    2006-05-20 20:49:28 補充:

    for(int i = 0; i < 127; i++) { printf("code %d appears %d time(s).\n", i, count[i]); } return 0;}

Still have questions? Get your answers by asking now.