Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code::Blocks. conio.h cprintf does not work

Tags:

c

codeblocks

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) ===|

like image 684
user3807592 Avatar asked Nov 22 '25 19:11

user3807592


1 Answers

<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');
like image 165
Am_I_Helpful Avatar answered Nov 25 '25 10:11

Am_I_Helpful