I am new to C programming. When I include the blank.h file into the Test.c file the program will not compile, however when I include blank.c file into the Test.c file it compiles fine. Below is the source for all the .c and .h files. Im using gcc as my compiler, and I have a feeling I need to do some sort of linking with it? Any help would be great thanks!
This is the Test.c source
#include <stdio.h>
#include "blank.h"
#include "boolean.h"
int main()
{
bool result = blank("");
printf("%d\n", result);
return 0;
}
This is the blank.h source
// Header file for blank function
bool blank(char string[]);
This is the blank.c source
#include "boolean.h"
#include "blank.h"
#include <regex.h>
bool blank(char string[])
{
regex_t regex_blank;
int blank = regcomp(®ex_blank, "[:blank:]", 0);
blank = regexec(®ex_blank, string, 0, NULL, 0);
if ( string == NULL || blank == 1 )
return true;
else
return false;
}
and finally the boolean.h
// Boolean
// Define true
#ifndef true
#define true 1
#endif
// Define false
#ifndef false
#define false 0
#endif
typedef int bool;
Ok, so I tried the source code you provided. There were a couple problems. Here are the exact steps of how I built, what I fixed. See if this works for you:
Created 4 files in a folder: Test.c, blank.c, blank.h and boolean.h
Copied code over.
From the shell ran:
Output:
To fix the first error:
In blank.h added this on top:
#include "boolean.h"To fix the second error:
In blank.c added this after the other includes:
#include <stdlib.h>Once again the terminal ran:
then from the terminal ran ./b and it prints 1.