# Output of this program explained?

Page 1 of 1

## 4 Replies - 466 Views - Last Post: 19 February 2015 - 09:53 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=370660&amp;s=f1a595474fd9133775d08187ad927c6f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rossryan

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 19-February 15

# Output of this program explained?

Posted 19 February 2015 - 03:47 PM

So I'm in an intro to C class and have an exam tomorrow and the teacher gave us a past exam to use as a practice test. I've put this program into XCode and it's not printing out any output so honestly I'm just really confused about everything regarding this problem. Any help at all would be appreciated. Here's the code but I've also attached it as an image.

```#include <stdio.h>

#include <ctype.h>
int main() {
int index, freq[26], c, stars, maxfreq;
for (index=0; index<26; index++)
freq[index] = 0;
while ( (c = getchar()) != '7') {
if (isalpha(c))
freq[tolower(c)-'a']++;
}
maxfreq = freq[25];
for (index = 24; index >= 0; index--) {
if (freq[index] > maxfreq)
maxfreq = freq[index];
}
printf("a b c d e f\n");
for (index=0; index<5; index++) {
for (stars=0; stars< (maxfreq - freq[index]); stars++)
printf(" ");
for (stars=0; stars< (freq[index]); stars++)
printf("*");
printf("%c  \n", ('A' + index) );
printf(" \n");
}
return 0;
}
```

This post has been edited by jimblumberg: 19 February 2015 - 03:53 PM
Reason for edit:: Added missing code tags please learn to use them properly.

Is This A Good Question/Topic? 0

## Replies To: Output of this program explained?

### #2 #define

• Duke of Err

Reputation: 1853
• Posts: 6,671
• Joined: 19-February 09

## Re: Output of this program explained?

Posted 19 February 2015 - 06:57 PM

I ran it with the input aaBcc*cC7, and its output seems ok.

You could try printing the input as a first check.
Was This Post Helpful? 1

### #3 rossryan

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 19-February 15

## Re: Output of this program explained?

Posted 19 February 2015 - 07:44 PM

#define, on 19 February 2015 - 06:57 PM, said:

I ran it with the input aaBcc*cC7, and its output seems ok.

You could try printing the input as a first check.

Sorry this is the dumbest question in the world I'm so new to C and its like an online course so I'm kinda going downstream without a paddle here. Where would I put "aaBcc*cC7" into the code? I'm confused about where it would go :\\
Was This Post Helpful? 0

### #4 rossryan

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 19-February 15

## Re: Output of this program explained?

Posted 19 February 2015 - 07:51 PM

Hi sorry this is possibly the dumbest question in the world but I'm in an online C class and I've just started so its basically self taught and I'm confused about the most basic things just trying to get into it, but in this problem, where would I place the input for it to run properly? Thank you! I've attached a picture of the problem and also the code.
```#include <stdio.h>
#include <ctype.h>
int main() {
int index, freq[26], c, stars, maxfreq;
for (index=0; index<26; index++)
freq[index] = 0;
while ( (c = getchar()) != '7') {
if (isalpha(c))
freq[tolower(c)-'a']++;
}
maxfreq = freq[25];
for (index = 24; index >= 0; index--) {
if (freq[index] > maxfreq)
maxfreq = freq[index];
}
printf("a b c d e f\n");
for (index=0; index<5; index++) {
for (stars=0; stars< (maxfreq - freq[index]); stars++)
printf(" ");
for (stars=0; stars< (freq[index]); stars++)
printf("*");
printf("%c  \n", ('A' + index) );
printf(" \n");
}
return 0;
}
```

#### Attached image(s)

This post has been edited by modi123_1: 19 February 2015 - 09:00 PM
Reason for edit:: please use the code tag button in the editor

Was This Post Helpful? 0

### #5 #define

• Duke of Err

Reputation: 1853
• Posts: 6,671
• Joined: 19-February 09

## Re: Output of this program explained?

Posted 19 February 2015 - 09:53 PM

Hi, yes these things can be confusing at the beginning.

Usually when a program is run, you enter input. This will be a console application/program. Console is a term for the keyboard and screen together (standard input and output).

You create a project in an IDE (XCode), which contains your source code (C++), this you build (compile and link) to an executable file that the computer can run/understand. If this is a console program you can run it in a console window. The executable is a file which can be run from disk.

The program can usually be run from disk (console window/terminal) or the IDE (Integrated Development Environment).

I am not familiar with XCode, unfortunately. There a various ways running the program usually.

Under Project there is Source, Documentation and Products. In Products should be your executable program, if the build was successful. You maybe able to run it from there.

There maybe a Run menu section/item.

Keyboard shortcut to run seems to be CMD R or CMD shift R.

You could put a prompt before the while loop to see if that helps.

```printf("Enter numbers : \n");

```

That's somethings to try anyway, see how you get on.
Was This Post Helpful? 1

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }