while ((ch=getchar())!=EOF)
{
...random code....
ch=getchar();
}I have included a printf in the code that prints the letter that getchar() gets. The problem is that I got that letter printed infinite times :mad:Help please?
while ((ch=getchar())!=EOF)
{
...random code....
ch=getchar();
}I have included a printf in the code that prints the letter that getchar() gets. The problem is that I got that letter printed infinite times :mad:|
|
|
WingedPanther said:
#include <stdio.h>
int main()
{
char ch;
int k, i = 1;
ch=getchar();
while ((ch)!=EOF)
{
if ((ch>=0) && (ch<=9))
if (i = 1)
k = (int)ch ;
else
k = k * 10 + (int)ch ;
i++ ;
if ((ch>='a') && (ch<='z') || (ch>='A') && (ch<='Z'))
{
for (i=1; i++; i=k)
{
printf("%c", ch) ;
}
i = 1 ;
}
ch=getchar();
}
}
while ((ch = getchar())!=EOF)
{
// blabla
}
Ancient Dragon said:
while ((ch = getchar())!=EOF)
{
// blabla
}
if ((ch>=0) && (ch<=9))when you enter the digit 5 it is read by getchar() as the character '5', not the number 5. So the above check should be as follows: Note the single quote marks.
if ((ch>='0') && (ch<='9'))
for (i=1; i++; i=k)
if( isdigit(ch) )
{
k = ch - '0';
}