getchar()

getchar()

When i write he following program in C using turboC compiler, program repeatedly asks me to input, i want the program to take input once, show the result and stop, pleae help.

#include<stdio.h>
main() {
int c;
while( (c=getchar())!=EOF) { putchar(c); }
}
View Answers

February 9, 2010 at 11:52 AM

#include<stdio.h>
#include<conio.h>
void reverse(void)
{
char c;
if((c=getchar())!='\n')
reverse();
putchar(c);
return;
}
void main()
{
clrscr();
printf("\nEnter the line whatever u want to reverse:");
reverse();
getch();
}

February 9, 2010 at 11:53 AM

Hi Friend,

Try the following:

#include<stdio.h>
#include<conio.h>
void main() {
char c;
c=getchar();
putchar(c);
getch();
}

Thanks









Related Tutorials/Questions & Answers:

Ads