If you use CodeBlock for compelling C/C++ programs you might face this kind of warning
suppose, if you got warning such as “implicit declaration of function ‘exit’ “ that means you need to include header file #include<stdlib.h> before you use exit function in any program
for example, consider below program
#include <stdio.h> //#include <stdlib.h> int main () { FILE *fp;// file pointer fp int length; fp = fopen("text.txt", "r"); if(fp==NULL) // check if the file contain NULL character { printf("\n file cannot be open"); // if yes then print, file cannot be open exit(1); } fseek(fp, 0, SEEK_END); length = ftell(fp); fclose(fp); printf("Total size of text.txt = %d bytes\n", length); return(0); }
Another example
You need to include header file <string.h> to use function strcpy otherwise, you might face error like “implicit declaration of function ‘strcpy’ “
#include <stdio.h> //#include <string.h> // you need to include header <string.h> to avoid implicit declaration int main() { char string1[10] = "hi_there"; char string2[10]; // copies the s1 to s2 strcpy(string2, string1); printf("%s",string2); return 0; }
Leave a Reply