thelearner
Programmer
Hi,
I have a program from the tutorial that is suppose to count
the lower case character. The tutorial said that I have to
enter control-d or control-z after the last line of my text
to indicate end of file. When I excecute my program, I got
a blank screen. Then I typed a line as below and hit enter.
This is my string. control-d
I did not get a message 'Press any key to continue ...' like in my other programs. Instead the cursor moved to the
next line. Look like it did not hit the end of file. How is
it suppose to work?
Thanks in advance
Here is my program
#include <stdio.h>
int main()
{
int i, j;
char input[120];
char *pt;
char alphabet[27] = "abcdefghijklmnopqrstuvwxyz";
int alphaCount[26];
for (i = 0; i < 26; i++)
{
alphaCount = 0;
}
while ((pt = gets(input)) != NULL)
{
for (i = 0; i < 120 && input != '\0'; i++)
{
for (j = 0; j < 26; j++)
{
if (input == alphabet[j])
{
alphaCount[j]++;
}
}
}
}
for (i = 0; i < 26; i++)
{
printf("found %d occurrences of %c\n", alphaCount, alphabet);
}
system("PAUSE");
return 0;
}
I have a program from the tutorial that is suppose to count
the lower case character. The tutorial said that I have to
enter control-d or control-z after the last line of my text
to indicate end of file. When I excecute my program, I got
a blank screen. Then I typed a line as below and hit enter.
This is my string. control-d
I did not get a message 'Press any key to continue ...' like in my other programs. Instead the cursor moved to the
next line. Look like it did not hit the end of file. How is
it suppose to work?
Thanks in advance
Here is my program
#include <stdio.h>
int main()
{
int i, j;
char input[120];
char *pt;
char alphabet[27] = "abcdefghijklmnopqrstuvwxyz";
int alphaCount[26];
for (i = 0; i < 26; i++)
{
alphaCount = 0;
}
while ((pt = gets(input)) != NULL)
{
for (i = 0; i < 120 && input != '\0'; i++)
{
for (j = 0; j < 26; j++)
{
if (input == alphabet[j])
{
alphaCount[j]++;
}
}
}
}
for (i = 0; i < 26; i++)
{
printf("found %d occurrences of %c\n", alphaCount, alphabet);
}
system("PAUSE");
return 0;
}