473,499 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using getchar

1 New Member
I want to use getchar in a while loop such that it does not dont want to press enter everytime how is this possible
for eg
while((c=getchar())!='\n')
{
printf("%c",c);
}
i want this variable c to be printed each time i press a character in run time and not pressing enter at all how is this possible i dont want my output at the end but simultaneously with pressing the character the character should be printed
Dec 5 '11 #1
3 1517
weaknessforcats
9,208 Recognized Expert Moderator Expert
Your program does not have control until the user presses enter. Any number of characters may be entered but the buffer is not available to you until the user presses enter.

You would need to write your own keyboard driver. Or you could write in Windows code and look for message WM_KEYDOWN.
Dec 5 '11 #2
donbock
2,426 Recognized Expert Top Contributor
stdin is commonly line buffered. This means that characters are collected (buffered) in the device driver until a newline is typed (for stdin). It sounds like you want stdin to be unbuffered. Take a look at stdio.h function setbuf and setvbuf.
Dec 7 '11 #3
gautham786
1 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. Code removed...}
  6.  
  7. }
Dec 7 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2228
by: Cam | last post by:
Hi everyone, Before I answer to a (hopefully) helpful reply to this post, I have been rapped over the knuckles for 'top-posting' and I do not wish to be a learner poster who observes poor...
6
1896
by: Luke Wu | last post by:
Whenever one runs across programs that use the return value from getchar() to read input, it's almost always accepted into an int-defined variable. I've read explanations on this and have always...
1
3690
by: White Spirit | last post by:
I'm trying to use getchar() to read alphanumeric data as follows:- char input; /* Take a string of input and remove all spaces therein */ int j = 0; while ((input = getchar()) != '\n') { if...
13
12372
by: broeisi | last post by:
Hello, Can someone help me out with this one? The following program should read characters till it met the EOF (-1) on my pc. I'm running linux and using the gcc compiler version 3.4.5. But...
20
2617
by: blufox | last post by:
This is a simple code snippet i used ... #include <stdio.h> int main(void) { int ch; do { printf("still yes...\n"); printf("\nenter choice :: "); ch = getchar(); }while(ch == 'y');
5
8696
by: Jonathan | last post by:
Hi-- I have the following code: #include <stdio.h> char a,b; int main()
6
5253
by: Alan | last post by:
I am using Standard C compiled with GCC under Linux Fedora Core 4 When I run this program and enter a character at the prompt, I have to press the ENTER key as well. This gives me 2 input...
25
5397
by: ehabaziz2001 | last post by:
Why I can not begin my subscript of character arrrays with 0. In this program I can not do : do { na=getchar(); i++; na=getchar(); } while (na!='\n');
7
6571
by: hey77 | last post by:
Write a program that counts number of braces, brackets and parenthesis in the standard input and tests where there are the, same number of left braces, { , as right braces, } ; same number of left...
9
5125
by: primeSo | last post by:
// FIRST int main(void){ int c, i = 0; char cArray; while( (c = getchar()) != '\n' && c != EOF){ cArray = c; i ++; }
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.