I've given an answer to the code but i can not understand some parts of it, the ones what i do not understand i mark it on [color=#FF0000]red[/color]
include
define IN 1
define OUT 0
define MAXLENGTH 11
int main()
{
int i = 0;
int j =0; /* i and j are simply index counters */
int c = 0;
int nchar = 0; /* number of characters in a word */
int inspace = IN; /* a flag to know whether we are inside of outside the word */
int wordlen[MAXLENGTH]; /* counts how many words of a particular length we have seen */
[color=#FF0000] for(i = 0; i < MAXLENGTH; ++i) //What are we doing here? Why setting up all the array to 0?
wordlen[i] = 0;[/color]
while((c = getchar()) != EOF) [color=#000000]// While you do not end writing --->[/color]
{
if(c == ' ' || c == '\t' || c == '\n') [color=#000000]//IF the char you wrote is a blank space, tab or new line[/color]
{
if (inspace == OUT) [color=#FF0000] //From here i do not understand what is going on[/color]
[color=#FF0000] {
if(nchar < MAXLENGTH)
++wordlen[nchar];
}
inspace = IN;
nchar = 0;
}
else
{
++nchar;
if(c == '"' || c == '\'')
--nchar;
inspace = OUT; [b]//Until here[/b]
}[/color]
}
/* printing the Horizontal-Histogram */
for(i = 1; i < MAXLENGTH; ++i)
{
printf("%2d| ", i);
for(j = 0; j < wordlen[i]; ++j)
putchar('*');
putchar('\n');
}
return 0;
}
My request is if someone could explain me those lines of code, i can not get it
Thanks!!