Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

anotherroger

macrumors newbie
Original poster
Oct 5, 2013
1
0
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]
 
Last edited by a moderator:
In this case you can just use getchar() which is part of the standard C library.
 
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."
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.