3
votes

Code being tried below:

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

int main(void)
{
  char ch;

  do{
    ch=getch();
    cprintf("%c", toupper(ch));
  } while(ch !='q');

  return 0;
}

error below:

C:\Users\Towsif\Desktop\C\sd\main.c||In function 'main':| C:\Users\Towsif\Desktop\C\sd\main.c|11|warning: implicit declaration of function 'cprintf' [-Wimplicit-function-declaration]| obj\Debug\main.o||In function main':| C:\Users\Towsif\Desktop\C\sd\main.c|11|undefined reference tocprintf'| ||=== Build finished: 1 errors, 1 warnings (0 minutes, 0 seconds) ===|

1
Well, is it in any of those headers? - Martin James
I'm guessing that you're using the GCC compiler and if I remember right conio.h is not supported with GCC. - jpw
Are you learning c? Maybe try a learning material that uses standard libraries as a learning basis?? The actual problem is interpreting the error msg and knowing what library etc but if you're first learning you need to move on away from this stuff, use printf etc and standard functions - Brandin
BTW if you really want there is an implementation of conio here (devs tested on Linux but it may also compile in mingw didn't try it yet). but again if your learning you should just stick to standard library before moving on to 3rd party stuff sourceforge.net/projects/linux-conioh - Brandin
Thanks @Brandin. Started to skip programs that need conio.h header to work. - user3807592

1 Answers

2
votes

<conio.h> header file is not available in GCC(MinGW/Cygwin) compiler. The error is not informative and is misleading.Try without using that header file...

EDIT :-

You can't use getch() and cprintf()! So, instead of them you try getchar() and printf(). Also, there is no need to change the compiler as GCC is considered the best compiler for C language. Actually, you should either skim that portion of book which requires these <conio.h> header files OR alternately just install another C-compiler alongside GCC. Don't remove GCC! Please use GCC only...

Try this code :-

do{
ch=getchar();    // changed getch() to getchar();
printf("%c", toupper(ch));   //changed cprintf() to printf();
} 
 while(ch !='q');