简体   繁体   中英

How to take console input for C/C++ program in Eclipse CDT

I have eclipse June CDT with gcc4 and gdb via cygwin on Windows7. I can't seem to taken input from the console. I searched around and it might be related to EOF for eclipse which might be resolved by unchecking "Connect process input & output to a terminal" in the Run/Debug configuration. But I can't seem to uncheck it.

Can anyone suggest best way to fix this issue.

#include <stdio.h>
#include <stdlib.h>

void menu();
int main(void) {


    menu();
    return 0;
}


void menu()
{
    int i=0;
     printf(" \n1. Push to Queue");
         printf(" \n2. Pop from Queue");
         printf(" \n3. Display Data of Queue");
         printf(" \n4. Exit\n");
         while(1)
         {
              printf(" \nChoose Option: ");
              scanf("%d",&i);
              switch(i)
              {
                    case 1:
                    {
                         int value;
                         printf("\nEnter a valueber to push into Queue: ");
                         scanf("%d",&value);
                        // push(value);
                        // display();
                         break;
                    }
                    case 2:
                    {
                        // delQueue();
                        // display();
                         break;
                    }
                    case 3:
                    {
                        // display();
                         break;
                    }
                    case 4:
                    {
                         exit(0);
                    }
                    default:
                    {
                         printf("\nwrong choice for operation");
                    }
              }
         }

}

Found a pair of relevant related SO questions:

Long story short, they are saying that cygwin is treated "differently" as a buffer compared with other OS's, and because of this the console is not as "interactive" as it (probably) should be. Some solutions recommend an explicit flush of the buffer, while others offer configuration options.

You need to configure the command line arguments for Eclipse: Under Run configurations>Arguments

Read here

Also consider using Ant as a build script. Works better in the long run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM