Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Identify blank line with gets() function!!

Identify blank line with gets() function!!

Scheduled Pinned Locked Moved C / C++ / MFC
questioncareer
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tongc
    wrote on last edited by
    #1

    Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); } Any ideas, helps or suggestions are highly appreciated!!! Regard,

    R G R 3 Replies Last reply
    0
    • T tongc

      Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); } Any ideas, helps or suggestions are highly appreciated!!! Regard,

      R Offline
      R Offline
      Roger Stewart
      wrote on last edited by
      #2

      getchar maybe what you need instead of gets. Roger Stewart "I Owe, I Owe, it's off to work I go..."

      1 Reply Last reply
      0
      • T tongc

        Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); } Any ideas, helps or suggestions are highly appreciated!!! Regard,

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #3

        Try something like this:

        char input[MAX_PATH];

        do {

        cout << "Enter the text " << endl;//prompt for the input
        
        gets(input);//store what the user types 
        
        if (strlen(input) != 0) {
        
            // ...
        
        }
        

        } while (strlen(input) != 0);

        Gary R. Wheeler

        1 Reply Last reply
        0
        • T tongc

          Hi I'd like to get the user's input from the console, if the user put in some text, this information will be put in a buffer, if the user type in nothing in and press enter then the program is terminated. But how do i know if the user has type in something??? i've attempted to play around with this, first with cin.getline, cin.get ...and finally come up with gets(), however it still seem has not done the job. this is the code that i've attempted char input[MAX_PATH]; char *pInput = input; cout << "Enter the text " << endl;//prompt for the input char delimeter =(char)gets(input);//store what the user types while( delimeter != '\r' ) { // int length = strlen(input); cout << "Enter the text " << endl; delimeter =(char)gets(input); } Any ideas, helps or suggestions are highly appreciated!!! Regard,

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          You may have problems mixing cin/cout and gets/printf. For console hacks, I use gets/printf. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups