473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem on getchar()...

Hi,
I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?

Then, another question:

Is there a specific function to exit program pressing any button?
I've tried this with getchar() function, but after I press a button, I
must press Enter too.

Thank you.
MargNat

Sep 18 '06 #1
3 5655
MargNat <ma*****@cashette.comwrote:
Hi,
I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?

Then, another question:

Is there a specific function to exit program pressing any button?
I've tried this with getchar() function, but after I press a button, I
must press Enter too.
If I want the user to press Enter, then I do:

std::string trash;
std::getline(std::cin, trash);

Of course, this requires #include <string>. It only requires the user
to press Enter, and does not require pressing another key before it.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Sep 18 '06 #2
MargNat wrote:
Hi,
I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?
Why what? You haven't shown any code or told us what "a way" and
"another way" mean. The crystal ball is in the shop this week.


Brian
Sep 18 '06 #3
MargNat <ma*****@cashette.comwrote:
>I've wrote a simple c++ program without graphic interface;
Now, if I build it with Visual Studio function getchar() works in a
way;
if I build it with Dev-C++ function getchar() works in another way.
Why?
getchar() is a macro rather than a function. This means there
is more likely to be inconsistent behavior, depending on how
you call it and depending on your system. Try using fgetc()
instead.

Steve
Sep 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: clusardi2k | last post by:
/* The below code on SGI will wait for you to enter 2 things, but on Linux it will only wait the first time. I can make the code work by replacing the scanf with: char data ; fgets...
13
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...
5
by: Jonathan | last post by:
Hi-- I have the following code: #include <stdio.h> char a,b; int main()
6
by: KOFKS | last post by:
I have come across a problem when I'm reading "comp.lang.c FAQ list · Question 12.1". This item is about char c; while((c = getchar()) != EOF) ... One paragraph of the item writes:"If type...
11
by: shekhardeodhar | last post by:
The program compiles properly (most of it is from k&r) but the second function (here character_count) gives wrong answer. Can someone please explain why ? #include<stdio.h> #define IN 1...
25
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');
14
by: arnuld | last post by:
i have slightly modified the programme from section 1.5.1 which takes the input frm keyboard and then prints that to the terminal. it just does not run and i am unable to understand the error...
20
by: Senthil-Raja | last post by:
The getchar() function is expected to fetch the next character in the input stream and return it. But, when I wrote a program using this function, it looks like the reading of the input stream...
9
by: primeSo | last post by:
// FIRST int main(void){ int c, i = 0; char cArray; while( (c = getchar()) != '\n' && c != EOF){ cArray = c; i ++; }
2
by: Raj | last post by:
Following is a code to print integer equivalent of a hexadecimal number. If the entered number starts with a 0x or a 0X, calculation is done after skipping these two characters. Now, this code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.