473,385 Members | 1,630 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,385 software developers and data experts.

Reading input doesn't work

NaN
Hi I'm using Dev-C++.

Here is my sourcecode.
/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/

#include <conio.h>
#include <ctype.h>

void main( void )
{
int ch;

_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );

_putch( ch );
_putch( '\r' ); /* Carriage return */
_putch( '\n' ); /* Line feed */
}

Can u help?
Jun 27 '08 #1
3 2551
NaN wrote:
Hi I'm using Dev-C++.

Here is my sourcecode.
/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/

#include <conio.h>
#include <ctype.h>

void main( void )
{
int ch;

_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );

_putch( ch );
_putch( '\r' ); /* Carriage return */
_putch( '\n' ); /* Line feed */
}

Can u help?
You have a bunch of non-standard, proprietary stuff here. You'll need a
Dev C++ forum of some sort. If I read it correctly, you want to get
individual keystrokes from the input. There's no standard way to do
that.

See the FAQs:

<http://c-faq.com/osdep/cbreak.html>


Brian
Jun 27 '08 #2
[Subject line: Reading input doesn't work]

NaN said:
Hi
Hi
I'm using Dev-C++.
Presumably you mean you're using a C compiler of some kind which happens to
have a few +s in its name. That's fine.
Here is my sourcecode.
Okay. Let me fix it for you.

/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/

#include <stdio.h>
#include <ctype.h>

int main(void)
{
int ch;
puts("Type 'Y' when finished typing keys.");
while((ch = toupper(getchar())) != EOF && ch != 'Y')
{
}

puts("Y");
return 0;
}

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #3
NaN <no@spam.invalidwrites:
Hi I'm using Dev-C++.
Presumably you're using it as a C compiler, not as a C++ compiler.
Here is my sourcecode.
/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/

#include <conio.h>
#include <ctype.h>

void main( void )
{
int ch;

_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );

_putch( ch );
_putch( '\r' ); /* Carriage return */
_putch( '\n' ); /* Line feed */
}

Can u help?
Please don't use silly abbreviations like "u". Take the time to type
out the whole word. Don't make reading your message more difficult
than it has to be.

Please put your question in the body of your message. Some
newsreaders don't make it easy to see the subject header while reading
a message. (Your subject was "Reading input doesn't work".)

Can we help with what exactly? You say it "doesn't work". There are
a nearly unlimited number of ways in which something can "not work".
You need to tell us what you expected what you got, and how they
differ; we're not mindreaders.

"void main(void)" needs to be "int main(void)". And since main()
returns an int, you should actually return an int; add "return 0;"
before the closing brace.

The following are non-standard:

<conio.h>
_cputs
_getch
_putch

The standard I/O routines are declared in <stdio.h>. Consult your
textbook for instructions on how to use them. Nothing you're trying
to do here (as far as I can tell) requires anything beyond standard C
features.

Assuming that _putch is intended to print a character to standard
output (or the console, or whatever), you probably don't need the
'\r'. A single '\n' character represents a new-line; it should be
translated as necessary for your system.

You only call _putch for a single character, followed by '\r' and
'\n'. Since the loop won't terminate until ch has the value 'Y', that
single character will inevitably be 'Y'. Without knowing what you're
trying to do, I can't guess whether that's what you want.

Suggested reading:

The comp.lang.c FAQ, at <http://www.c-faq.com/>.

Eric Raymond's "How To Ask Questions The Smart Way", at
<http://www.catb.org/~esr/faqs/smart-questions.html>.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #4

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

Similar topics

12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
3
by: Max | last post by:
Yea this is probably a n00b question, but I haven't programmed C++ in at least 2 years and have never programmed for unix, sorry :) Anyway, I have a project in which a program is required to read...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
28
by: Colin JN Breame | last post by:
Hi, Fairly new to C. What is the best way to read a line (\n terminated) from a file? Ive looked at fscanf but was not sure which format specifier to use. (%s perhaps). Thanks Colin
2
by: Matt McGonigle | last post by:
Hi all, Please help me out with this. Perhaps it is a dumb question, but I can't seem to make it work. I am doing a file conversion using an unformatted binary file for input and outputting to...
10
by: T Cordon | last post by:
I am using a StreamReader to read text from an HTML file and display it as part of a page in a Label Control. Buy it is not displaying characters as: ñ, ó, ú, etc. Please Help. Thanks
0
by: Miha | last post by:
I wrote a simple Windows Application based application in C# called the CallWebServiceGui. This application is started from a different application called WsGuiStarter. The WsGuiStarter redirects...
4
by: tushar.saxena | last post by:
Hi, I'm trying to read a file using the istearm class (I cant use ifstream since the input might be a file or it might be stdin). istream *input; // Add checks for file name here, else use...
4
by: zr | last post by:
Hi, i need to read a text file which contains a list of items, all of type ItemType, separated by whitespace and newlines. For each line, there will be a vector<ItemTypeobject that will store...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.