Results 1 to 3 of 3

Thread: getchar() running to infinte loop,its not responding when i run it.

  1. #1
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default getchar() running to infinte loop,its not responding when i run it.

    Hi,

    I'm using getchar() in qt-creator4 on linux-platform.Its going to an infinte loop,im not even able to enter the character,the system hangs so i force quit.Could someone please help me,how i can use getchar() in qt-creator4 on linux ?

    sample code:

    Qt Code:
    1. #include <iostream>
    2. #include <stdio.h>
    3.  
    4. int main()
    5. {
    6. char ch;
    7. printf( "Enter a character : ");
    8. ch=getchar();
    9. printf("Char is %c \n",ch);
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Actually i'm supposed to use getch(),but since getch() is not available in linux.I had to use getchar(). It would great ,if anyone could suggest me how i
    can use getch() in linux ? Along with the solution to the above problem.

    Thanks,
    Keerthi
    Last edited by wysota; 8th September 2011 at 23:33. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: getchar() running to infinte loop,its not responding when i run it.

    Nothing hangs, press enter/return. And when the program exits, type in "man getchar" and press enter again and start reading.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,589
    Thanks
    13
    Thanked 1,585 Times in 1,514 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: getchar() running to infinte loop,its not responding when i run it.

    Actually i'm supposed to use getch(),but since getch() is not available in linux.
    I think you are mistaken:
    Qt Code:
    1. $ man getch
    2. curs_getch(3X) curs_getch(3X)
    3.  
    4. NAME
    5. getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or push back) characters from curses
    6. terminal keyboard
    7. ...
    To copy to clipboard, switch view to plain text mode 
    You need to include the relevant curses header, initialise and cleanup curses, and link the curses library.

    If you intend turning this into a program that uses Qt then you almost certainly don't want either function.

Similar Threads

  1. QProgressDialogButton is not responding
    By gowen in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2011, 20:13
  2. Replies: 4
    Last Post: 6th August 2011, 02:40
  3. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 17:31
  4. Replies: 4
    Last Post: 26th June 2008, 19:41
  5. getchar()
    By mickey in forum General Programming
    Replies: 6
    Last Post: 20th October 2006, 18:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.