I have a header file, with just this line of code headerFile.h int headerFile (i
ID: 3610168 • Letter: I
Question
I have a header file, with just this line of codeheaderFile.h
int headerFile (int x, int y) I have definedthe function here
headerFile.c
#include <stdio.h>
#include <headerFile.h>
headerFile (int *x, int *y){ I realize naming the function thesame name as the files is not good
naming practice but I wasn't particularly feeling creative atthe time.
(*x)++;
(*y)++;
}
main ( ) {
int a, b;
a = b = 0;
headerTest (&a, &b);
printf ("a:%d b:%d ",a,b);
}
now I try to compile this like this
gcc headerTest.c headerTest.h -o testFile
I get this error
headerTest.c:2:24:error: headerTest.h : no such file ordirectory.
I don't see the problem, both files are quite clearly in the samedirectory... Any advice would be fantastic, will rate. Thanks inadvance!
Explanation / Answer
Problems with your program: 1)You named the header file as "headerFile.h" and source fileas "headerFile.c", you are using the command "gccheaderTest.c headerTest.h -otestFile" to compile the program in which you are usingheaderTest.h and headerTest.c which are non existing. so use "gcc headerFile.c headerFile.h -o testFile"to compile the program 2) The function declaration in header file returns an intvalue. int headerFile (int x, int y),put a semicolon after the function declaration. int headerFile (int x, int y); 3) The function definition given in the source file does not returna int value....so return some integer value in the functiondefinition. headerFile (int *x, int *y){ /* I realize naming the function the same name as the files isnot good naming practice but I wasn't particularly feeling creative atthe time. */ (*x)++; (*y)++; return 0; } 4) The function declaration consists of parameters withinteger value (int x , int y). But in the function definition youare using pointers to int....It will give a warning but not anerror. 5) In main() also you called the function... headerTest(&a, &b);change it to headerFile(&a, &b);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.