Skip to main content
GameDev.net gamedev.net
🔒 Locked

my own input

Started by silverphyre673 Nov 17, 2004 at 11:54 PM 1 replies 400+ views
Original Post
silverphyre673
silverphyre673
I am making a set of functions for my own use in a console-based program. I want to essentially create a "text based text box" where I can read each character the user sends as soon as they press the key. For example, with cin, the user enters a string. Now, if the string is too big to be held in the array you have them put it into, the program will crash. So I want to make an input function that gets each character one at a time, reads them, decides what to do with them, and THEN allows another character to be entered, like with getche in conio.h I would use conio, except I want to develop this on my linux box and conio is specifically for windows, as far as I can tell. Thanks.
my siteGenius is 1% inspiration and 99% perspiration
lemurion
lemurion
you could use std::string, it would be easier
#include <iostream>#include <string>int main(int argc, char *argv[]){  std::string input;    // this will stop at the first space  std::cin >> input;  std::cout << "Your input was: " << input << std::endl;  // this will get a whole line  std::getline(std::cin, input);  std::cout << "Your input was: " << input << std::endl;  return 0;}


hope that helps !
Matchu
Matt
Nice Coder
Nice Coder
You could use getch().

maybe something like

for (double x = 0; x < SIZE_OF_ARRAY - 1; arr[x++] = getch());arr[SIZE_OF_ARRAY] = '\0'


? That should fill up every element in the array, and store it all as a string (char array, similar thing).

Is that what you wanted?

perhaps something like

bool y;char x;While (y) {x = getchar();y = (x != '\n'))


Would be better?

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.