Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char *argv[]){
- int alphabetCount[26] = { 0 };
- float alphabetPerc[26] = { 0 };
- FILE *txtFile = fopen(argv[1], "r"); // open file that was dragged into exe
- char buffer;
- if (txtFile){
- while ( (buffer = toupper(fgetc(txtFile)) ) != EOF){
- if (buffer >= 'A' && buffer <= 'Z'){
- alphabetCount[ASCII_TO_ALPHA(buffer)]++;
- }
- }
- int som = 0;
- for (int i = 0; i < 26; i++)
- som += alphabetCount[i];
- for (int i = 0; i < 26; i++)
- alphabetPerc[i] = (float)alphabetCount[i]/som * 100;
- }
- fclose(txtFile);
- FILE *gnuplotPipe = popen("C:\\Users\\Zain\\Documents\\Github\\GNUCPlotter\\gnuplot\\bin\\gnuplot.exe -persistent", "w");
- fprintf(gnuplotPipe,
- "set multiplot\n"
- "set xrange [1:26]\n"
- "set autoscale\n"
- "show autoscale\n"
- "set grid\n"
- "set style data histogram\n"
- "set style histogram cluster gap 1\n"
- "set style fill solid border -1\n"
- "set boxwidth 0.9\n"
- "set xtic('A' 1, 'B' 2, 'C' 3, 'D' 4, 'E' 5, 'F' 6, 'G' 7, 'H' 8, 'I' 9, 'J' 10, 'K' 11, 'L' 12, 'M' 13, 'N' 14, 'O' 15, 'P' 16, 'Q' 17, 'R' 18, 'S' 19, 'T' 20, 'U' 21, 'V' 22, 'W' 23, 'X' 24, 'Y' 25, 'Z' 26)\n"
- "set xtic rotate by -45 scale 0\n");
- fprintf(gnuplotPipe, "plot '-' u 1:2 with boxes notitle, '' u 1:2:2 with labels offset char 0,1\n");
- char c = 'A';
- for (int i = 0; i < 26; i++){
- fprintf(gnuplotPipe, "%d %.2f\n", i+1, alphabetPerc[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement