Results 1 to 2 of 2

Thread: getch, getche, putch etc in gcc

  1. #1
    Join Date
    Jun 2011
    Location
    Mangalore, India
    Posts
    1

    Post getch, getche, putch etc in gcc

    I was using my college's unix server (ubuntu presumably) to compile programs in the laboratory. Now, i have installed Opensuse 11.4 with gnome3. I have installed the Developers pattern, and almost all the packages that looked relevant (which came up when i searched for libgc , gcc, and all). Now, i cant compile a program:
    Code:
    /*program to test file I/O and getch/putch functionaliny in gcc*/
    #include<stdio.h>
    int main()
    {       FILE *fi;
            char ch;
            char in;
            fi = fopen("infile","r");
            int countr=0,counterr=0;
            in='0';
            while(in!='\n')
            {
                    ch=fgetc(fi);
                    if(ch=='\n')
                            continue;
                    else
                    {
                            in=getch();
    
                            if(in==ch)
                            {
                                    putch(in);
                                    countr++;
                                    counterr--;
                            }
                           else
                            {
                                    counterr++;
                                    continue;
                            }
                    }
    }
    I am a beginner in programming, so any free advice is also welcome.
    Oh, the error is:
    Code:
    siddhartha@suse:~/Documents/programs> gcc typeprac.c
    /tmp/ccQHPVwJ.o: In function `main':
    typeprac.c:(.text+0x50): undefined reference to `getch'
    typeprac.c:(.text+0x6c): undefined reference to `putch'
    collect2: ld returned 1 exit status
    Thank you.

  2. #2
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    4,654

    Default Re: getch, getche, putch etc in gcc

    To my knowledge putch and getch are MS DOS console functions in C (so they
    do not exist on a linux system). I think you should use putchar and getchar
    instead.
    See
    Code:
    man getchar
    man putchar
    for explanations.

    --
    PC: oS 11.3 64 bit | Intel Core2 Quad Q8300@2.50GHz | KDE 4.6.4 | GeForce
    9600 GT | 4GB Ram
    Eee PC 1201n: oS 11.4 64 bit | Intel Atom 330@1.60GHz | KDE 4.6.4 | nVidia
    ION | 3GB Ram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •