How do I use getche() in C with Xcode?

Discussion in 'Mac Programming' started by anotherroger, Oct 5, 2013.

  1. anotherroger, Oct 5, 2013
    Last edited by a moderator: Oct 5, 2013

    anotherroger macrumors newbie

    Oct 5, 2013
    I'm trying to use the function "getche()", which is a non-standard instruction to retrieve an entry from the keyboard with a display, but Xcode dosen't take it.
    It shows:
    [FONT="Courier New"][I][I]Undefined symbols for architecture x86_64:
      "_getche", referenced from:
          _main in main.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Does somebody knows how to use that function or knows an alternative function?

    basically, my program asks a sentence then counts which letters are used and how many times.
    [FONT="Courier New"]#include <stdio.h>
    #include <ctype.h>
    int main(void)
    	int ltrs[27] = {0}, i;
    	char key;
    	int getche(void);
    	printf("Enter a sentence.\n");
    		key = getche();
    		if(key >= 'A' && key <= 'Z')
    			ltrs[key - 'A']++;
    	while (key != '.' && key != '!' && key != '?');
    	for (i = 0 ; i < 27 ; i++)
    		if (ltrs[i] > 0)
    			printf("\nthe lettrer %c = %d",i+'A',ltrs[i]);
    	return 0;
  2. subsonix macrumors 68040

    Feb 2, 2008
    In this case you can just use getchar() which is part of the standard C library.
  3. Senor Cuete macrumors 6502

    Nov 9, 2011
    Conio.h on Wikipedia

    "conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not described in The C Programming Language book, and it is not part of the C standard library, ISO C nor is it defined by POSIX."

Share This Page