473,563 Members | 2,735 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=getcha r())!='\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 1518
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
2236
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 netiquette as I am a firm believer in consideration .... to this end, could somebody please tell me how I reply to a message without top-posting? Do I...
6
1901
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 used this form. Recently, someone asked me why an int was needed, since -1 (usually EOF) can be safely represented in a signed char value. In...
1
3701
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 (!isspace(input)) j++;
13
12385
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 it doesn't. Am I doing something wrong here?.
20
2632
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
8722
by: Jonathan | last post by:
Hi-- I have the following code: #include <stdio.h> char a,b; int main()
6
5265
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 characters - 'a' and '\n' (Hex 61 and 0a) It seems as though the getchar() function needs ENTER to terminate reading stdin. I am trying to get the...
25
5420
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
6579
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 brackets, ; same number of left parentheses, ( , as right parentheses, ) i am required to use the getchar and putchar funtions......but dont...
9
5136
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
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5208
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.