i want to scan in a char y or n.
i use scanf("%c",&ans); when i press y or n the y on n shows up on the screen. is there any way to scan in the char without displaying what was pressed.
i want to scan in a char y or n.
i use scanf("%c",&ans); when i press y or n the y on n shows up on the screen. is there any way to scan in the char without displaying what was pressed.
A nonstandard function called getch() does this, what platform are you using?
-Prelude
My best code is written with the delete key.
i am using microsoft visual c++ to compile and i want to run it in dos
You do realize that MSVC++ comes with a handy set of CDs called the MSDN that have tons of information in them, right?Originally posted by the_head
i am using microsoft visual c++ to compile and i want to run it in dos
Quzah.
Hope is the first step on the road to disappointment.
>i am using microsoft visual c++
Then you have getch, include <conio.h>.
-Prelude
My best code is written with the delete key.
i dont have the cds
When i find myself in times of trouble. mother mary comes to me, speaking words of wisdom, let it be C
I guess you should actually buy your copy next time.Originally posted by the_head
i dont have the cds
Quzah.
Hope is the first step on the road to disappointment.
Here is a program with comments to help you get started and you can also go to msdn online for more help too. type it in the search engine google, some people are just not as courteous as others.
hope this helps you.
cj
[code]
/*
/* Program: Counting words
*/
#include<stdio.h>
#include<ctype.h>
int found_next_word(void);
int main(void)
{
int word_count = 0; /* initilizes the count to 0 */
while (found_next_word() == 1) /*detects a word as long as 1 has been returned*/
++word_count; /*increases word count if aword has been detected*/
printf("Number of words = %d\n\n", word_count);
int found_next_word(); /* fct call */
return 0; /*program completed successfully*/
}
int found_next_word(void) /* fct definition */
{
int c;
while (isspace(c = getchar())) /*reads a character from the keyborad
and as long as charcter is not a white space,
the body of the while loop is executed */
; /*skip white space */
if (c != EOF) { /*found next word */
while ((c = getchar()) != EOF && !isspace(c))
; /*skip all except EOF and white space */
return 1; /*progran not completed successfully*/
}
return 0; /*progran completed successfully*/
}
[\code]
cj