473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

15 New Member
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 2978
Banfa
9,065 Recognized Expert Moderator Expert
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
2356
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 ideas, and maybe write up an article later. AOP is not just buzzword. It's not just callback, it's not just Ruby's MixIn, it's not just Python's...
20
5910
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 making comparisons. If you have a file, in Python you could do:
6
1829
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 the end if you want to reuse it on many aspx pages) (notice closing brace) (start) <%}
2
2782
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 solaris), does there exists any kind of midware like odbc? 2. I search on the internet, and find most of the examples are based on PHP. Is there any c++...
11
3577
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 appreciated. Enter an interesting string. Too many cooks spoil the broth Error opening C:\myfile.txt for writing. Program termnated. This...
5
1730
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
3177
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 where my program is. When compiling my program two windows are poping up. The first one is saying "Total errors 0" and "Size of
3
1602
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. } template<typename R,typename A,R (*pFunc)(A)>
7
2664
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 says something about there not seeming to be a GNU make file in path or in Dev C++ bin path. how do i get this GNU make file etc.
9
2914
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 arrays objects etc.. Any way, I encountered a strange logic error and kinda put it to the side until now. This code is supposed to role the die,...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.