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

    Joined:
    Oct 5, 2013
    #1
    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:
    Code:
    [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)
    [/I][/I][/FONT]
    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.
    Code:
    [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");
    	
    	do
    	{
    		key = getche();
    		toupper(key);
    		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;
    }[/FONT]
     
  2. subsonix macrumors 68040

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

    Joined:
    Nov 9, 2011
    #3
    Conio.h on Wikipedia

    https://en.wikipedia.org/wiki/Conio.h:

    "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