Header files won't work in C [closed]

喜夏-厌秋 提交于 2019-12-17 20:32:18

问题


I'm using Dev-CPP, (but programming in C), and the header files won't work. I've gone to compiler option; directories; c inludes and checked the directory is correct, and it is. The include files are stored in C:\Dev-Cpp\include and that's where it's set to receive them.

For example:

#include <conio.h>

int main(int argc, char *argv[])
{
  textcolor(1);

  printf("Why won't header files work? \n");

  system("PAUSE");  
  return 0;
}

I've tried with several other header files, but they also don't work. I'm sure the answer is really obvious, but I'm clearly too stupid to fix this. I'm also using MinGW as the compiler, (comes standard with dev-cpp). Please help me.


回答1:


textcolor() very old.(Perhaps borland c++ ?)

e.g. redefine like this

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

void textcolor(unsigned short color){
    HANDLE hStdout;
    WORD wAttributes;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

    GetConsoleScreenBufferInfo(hStdout, &csbi);

    wAttributes = color ;
    if (color & 0x08) wAttributes |= FOREGROUND_INTENSITY ;

    SetConsoleTextAttribute(hStdout, wAttributes);
}

/*
#define FOREGROUND_BLUE      0x0001
#define FOREGROUND_GREEN     0x0002
#define FOREGROUND_RED       0x0004
#define FOREGROUND_INTENSITY 0x0008

#define BACKGROUND_BLUE      0x0010
#define BACKGROUND_GREEN     0x0020
#define BACKGROUND_RED       0x0040
#define BACKGROUND_INTENSITY 0x0080
*/

int main(int argc, char *argv[]){
    textcolor(1);
//  textcolor(FOREGROUND_BLUE);
    printf("FOREGROUND_BLUE \n");

    textcolor(4);
    printf("FOREGROUND_RED \n");

    textcolor(7);
    system("PAUSE");  
    return 0;
}



回答2:


conio.h header file doesn't work with dev cpp because it is not part of c standard. http://www.bloodshed.net/dev/faq.html



来源:https://stackoverflow.com/questions/21585206/header-files-wont-work-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!