| | |
Help with input
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
Originally Posted by Asif_NSU
"EOF"
>>I did try that too. But the problem is when i signal the EOF it stops taking input alright but doesnt take any other inputs after that. Say after inserting the page numbers the user might want to go back to the main menu and then from their might choose to search for a word in the dictionary, but using EOF as the end condition doesnt let u do that. So any other suggestions?
#include <stdio.h>
int main ( void )
{
int i, number;
for ( i = 0; i < 3; ++i )
{
fputs ( "page number(s) ? ", stdout );
fflush ( stdout );
while ( scanf ( "%d", &number ) == 1 )
{
printf ( "number = %d\n", number );
}
rewind ( stdin );
}
return 0;
}
/* my output
page number(s) ? 12 23 34 45^Z
number = 12
number = 23
number = 34
number = 45
page number(s) ? 78 89 90^Z
number = 78
number = 89
number = 90
page number(s) ? 1 2 3^Z
number = 1
number = 2
number = 3
*/•
•
Join Date: Nov 2004
Posts: 5
Reputation:
Solved Threads: 0
Hey everyone,
You all are high level programmers..and i'm really just a begginer in front
of you all but still if i might ask Asif why dont you use the function
which scan keys, as they do in programming games.
char ch;
ch=getch();
if(ch==13)
{....}
13 is the ascii code for Enter Key..
Is it possible this way?
You all are high level programmers..and i'm really just a begginer in front
of you all but still if i might ask Asif why dont you use the function
which scan keys, as they do in programming games.
char ch;
ch=getch();
if(ch==13)
{....}
13 is the ascii code for Enter Key..
Is it possible this way?
•
•
•
•
Originally Posted by Neo99
You all are high level programmers..and i'm really just a begginer in front
of you all but still if i might ask Asif why dont you use the function
which scan keys, as they do in programming games.
•
•
•
•
Originally Posted by Dave Sinkula
I suppose you could write your own input functions, but that seems like much more work than reading and parsing a line.
•
•
•
•
Originally Posted by Neo99
char ch;
ch=getch();
if(ch==13)
{....}
13 is the ascii code for Enter Key..
This is just an example, but demonstrates reading in and outputing to( could be file or whatever) the screen. Enter the numbers you want seperated by a space. when you are finished hit enter then crtl + z and enter key again to output to the screen.
C Syntax (Toggle Plain Text)
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <iterator> using namespace std; int main() { // create a string vector // inialized by all the words from standard input vector<string> v((istream_iterator<string>(cin)), istream_iterator<string>()); //sort elements sort( v.begin(), v.end() ); //print all elements ignoring subsquent duplicates unique_copy( v.begin(), v.end(), ostream_iterator<string>(cout, "\n") ); return 0; }
big146
why is everyone so much into STL?
Did i not explain why i dont want to use STL? Cos i m not into it yet. My knowledge on C++ is limited. Well what the heck, i have done it by parsing -- seems like that's the best way (without STL ofcourse). The thing is i encounter this type of problems so often that i wanted to know if there were any easy alternatives. Becos my knwoledge on C++ is limited i thought u guys would suggest something i did not know but was very simple to use. And in return i get codes that are either STL or uses advance techniques that are no easier than the parsing(using getchar() -- platform independent
). So back to old dog's trick. Thanx for the help though.
Did i not explain why i dont want to use STL? Cos i m not into it yet. My knowledge on C++ is limited. Well what the heck, i have done it by parsing -- seems like that's the best way (without STL ofcourse). The thing is i encounter this type of problems so often that i wanted to know if there were any easy alternatives. Becos my knwoledge on C++ is limited i thought u guys would suggest something i did not know but was very simple to use. And in return i get codes that are either STL or uses advance techniques that are no easier than the parsing(using getchar() -- platform independent
). So back to old dog's trick. Thanx for the help though. ![]() |
Similar Threads
- PHP Form Input (PHP)
- need input or suggestions for new website-thx (Website Reviews)
- i want the user to enter an input without obligating him to press enter (C++)
- Input Signal Out of Range (Windows NT / 2000 / XP)
- Tab control on hidden input fields (HTML and CSS)
Other Threads in the C Forum
- Previous Thread: need help outputting arrays
- Next Thread: Help on assignment
Views: 3301 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for C
* api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax database directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked reversing scheduling segmentationfault send single socketprogramming spoonfeeding standard strchr string student suggestions system test testautomation testing unix urboc user whythiscodecausesegmentationfault win32api windowsapi






