473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

can someone tell me why nothing happens when I run this(codeblocks)program on my mac?

15
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cctype>
  5. using namespace std;
  6.  
  7. //function prototypes
  8. void initialize(int [], int);
  9. int readData(char [], int, int [], int);
  10. void printResults(char [], int, int [], int, int);
  11.  
  12. //constant global variables used for arrays
  13. const int LIMIT = 27;
  14. const int ALPHA = 26;
  15. int main()
  16. {
  17.     char alphabet[ALPHA];
  18.     int count[LIMIT];
  19.     int total;//holds the total number of characters in the file
  20.  
  21.     //sets each letter in the alphabet to a subscript in the alphabet array
  22.     alphabet[0] = 'A';
  23.     alphabet[1] = 'B';
  24.     alphabet[2] = 'C';
  25.     alphabet[3] = 'D';
  26.     alphabet[4] = 'E';
  27.     alphabet[5] = 'F';
  28.     alphabet[6] = 'G';
  29.     alphabet[7] = 'H';
  30.     alphabet[8] = 'I';
  31.     alphabet[9] = 'J';
  32.     alphabet[10] = 'K';
  33.     alphabet[11] = 'L';
  34.     alphabet[12] = 'M';
  35.     alphabet[13] = 'N';
  36.     alphabet[14] = 'O';
  37.     alphabet[15] = 'P';
  38.     alphabet[16] = 'Q';
  39.     alphabet[17] = 'R';
  40.     alphabet[18] = 'S';
  41.     alphabet[19] = 'T';
  42.     alphabet[20] = 'U';
  43.     alphabet[21] = 'V';
  44.     alphabet[22] = 'W';
  45.     alphabet[23] = 'X';
  46.     alphabet[24] = 'Y';
  47.     alphabet[25] = 'Z';
  48.  
  49.     initialize(count, LIMIT);//call funtion
  50.     total = readData(alphabet, ALPHA, count, LIMIT); //call function
  51.     printResults(alphabet, ALPHA, count, LIMIT, total); // call function
  52.     //system("pause");
  53.     return 0;
  54. }
  55.  
  56. //this function initializes the counts in the array to 0. It accpes the count
  57. //array and the number of elements in the array, which is n.
  58. void initialize(int count1[], int n)
  59. {
  60.     for(int i=0; i<n; i++)
  61.        count1[i] = 0;
  62. }
  63.  
  64. //this function opens the input file and reads a character at a time using the
  65. //get() function. It reads from the file until there is no more information to
  66. //be read, in which case the while loop ends. this function accepts the alphabet
  67. //array, the number of elements in that array, which is c, the count array, and
  68. //the number of elements in that array, which is m.
  69. int readData(char brr[], int c, int count2[], int m)
  70. {
  71.     char x;
  72.     int counter = 0;
  73.  
  74.     ifstream infile;
  75.     infile.open("jkprogram.txt");//opens the input file
  76.     infile.get(x);//reads a character from the file
  77.     x = toupper(x);
  78.     while(infile) //reads from the file until there is nothing else to be read
  79.       {
  80.          for(int z=0; z<c; z++)//goes through every letter in the array
  81.            {
  82.               //if the read in character matches a letter in the alphabet
  83.               if(x == brr[z])
  84.                 count2[z]++; //increments the count if there is a match
  85.            }
  86.          //tests if the same read in character is not a letter or white space
  87.          if(isalpha(x) == false && isspace(x) == false)
  88.            //if not a letter or white space, increments the count for "other",
  89.            //which is the last subscript in the count array. Notice the
  90.            //subscript in the count array is 1 more than the alphabet array.
  91.            count2[m-1]++;
  92.          if(isspace(x) == false)//tests if read in character is a white space
  93.            counter++; //keep track of total number of characters
  94.          infile.get(x);//read in next character
  95.          x = toupper(x);//changes the read in character to uppercase, which in
  96.                         //this case ignores the case of the letter
  97.       }
  98.     infile.close(); //closes the file
  99.     return counter;//returns the total number of characters in the file
  100. }
  101.  
  102. //this function displays the letters and their counts.  It accepts the alphabet
  103. //array, which is crr, the number of elemetns in that array, which is d, the
  104. //count array, which is count3, the number of elements in that array, which is
  105. //p, and the total number of characters in the file, which is counttotal.
  106. void printResults(char crr[], int d, int count3[], int p, int counttotal)
  107. {
  108.     ofstream outfile;
  109.     outfile.open("histogram.txt"); //opens the output file
  110.     float percent;
  111.  
  112.  
  113.     outfile.setf(ios::fixed, ios::floatfield);
  114.     outfile.precision(2);//sets the number of decimal places to be shown
  115.     outfile.width(15);//sets the width of where to display the information
  116.     outfile << "Letter";
  117.     outfile.width(15);
  118.     outfile << "Occurrences";
  119.     outfile.width(15);
  120.     outfile << "Percentage" << endl;
  121.     outfile << "--------------------------------------------------------------";
  122.     outfile << endl;
  123.     for(int b=0; b<d; b++)//goes through the elements in the array
  124.       {
  125.          outfile.width(15);
  126.          outfile << crr[b];//displays each letter in the alphabet array
  127.          outfile.width(15);
  128.          outfile << count3[b];//displays the count of each letter
  129.          outfile.width(15);
  130.  
  131.          percent = static_cast<float>((count3[b]*100))/counttotal;
  132.          outfile << percent << "%" << endl;
  133.       }
  134.  
  135.       outfile.width(15);
  136.       outfile << "Other";
  137.       outfile.width(15);
  138.       outfile << count3[p-1]; //displays the last count in the count array
  139.       outfile.width(15);
  140.  
  141.       percent = static_cast<float>((count3[p-1]*100))/counttotal;
  142.       outfile << percent << "%" << endl;
  143.  
  144.     outfile.close();//closes the output file
  145. }
Apr 17 '10 #1
1 2968
Banfa
9,065 Expert Mod 8TB
Works for me, it is probably not finding your input file after attempting to open a file you should check to see if it has opened and output an error message if it has not.
Apr 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hung Jung Lu | last post by:
Hi, I have been looking into AOP (Aspect-Oriented Programming) for sometime, now. I frankly don't like the syntax of any of the approaches I have seen so far. I am kind playing around with some...
20
by: Hung Jung Lu | last post by:
Hi, I know people have talked about it before, but I am still really confused from reading the old messages. When I talk about code blocks, I am not talking about Lisp/Ruby/Perl, so I am not...
6
by: John Rivers | last post by:
hi, here is how to do it and restore sanity to aspx html rendering: (please only reply with sensible architectural discussion - juan) put this at the end of an aspx file (or use an include at...
2
by: xiaotom | last post by:
I want my software to be independant of operation system and databases. That's why I want to use odbc, and don't want to use MFC. Here I have some questions to ask: 1. On unix (like sun...
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
5
by: zika.ondra | last post by:
Please could someone write me in which program should I start programin? I tried to write the source in notepad and than save it as *.exe file but it didn't work. Help me please, Thanks.
7
by: Nena | last post by:
Hi there, I'm trying to include the Numerical Recipes for C++ for the Dev-C++ Editor Version. But so far I've failed. Therefore I've copied all head-files (for example nr.h) into the folder...
3
by: linarin | last post by:
#include <iostream> using namespace std; typedef bool (*CallableFunction)(int argc,char* argv); void DefineMyFunction(const char* name,CallableFunction func){ //here do the define action. }...
7
by: rockz | last post by:
Hi, i know this might sound stupid but i keep getting this error each time when i compile! and have no idea what the comp is taking bout! please help! "system cannot find specified file" it also...
9
xpun
by: xpun | last post by:
hey all So I decided to be a little ambitious over the summer and create the game of clue in c. I figured it would give my self a GOOD refresher of the language and further understand functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.