Search code examples
ccodeblocksheader-files

C: Problem including a header file with CodeBlocks


I am having a problem with adding my header file "header.h" into my main file "main.c" (I am using CodeBlocks). The following is the minimal version where I can reproduce this error:

My main file looks like this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "header.h"

struct _My_Struct_
{
  char* name_;
  int id_;
};

struct _Struct_List_
{
    struct _My_Struct_ struct_list[50];
};


int loadFILE(const char* file_name)
{
  FILE* file = fopen(file_name, "r");

  if (file == NULL)
    return 2;

  char line[10];
  fgets(line, sizeof(line), file);

  return 0;
}


int main()
{
  printf("Something_1\n");
  printHelloMessage();
  printf("Something_2\n");

  char person_string[] = "FirstName LastName [3]";
  char* name = strtok(person_string, "[");
  char* id_string = strtok(NULL, "]");

  printf("name= %s and id_string = %s\n", name, id_string);

  return 0;
}

My header file "header.h" looks like this:

#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED

void printHelloMessage()
{
  printf("Hello!\n");
  printf("\n");
}

#endif // HEADER_H_INCLUDED

Running this problem leads to the error message

Process returned 32766 (0x7FFE)   execution time : 0.570 s
Press any key to continue.

I do not know what I am doing wrong, however, I noted that when I delete the struct part from main.c this works. Could you please tell me how to fix this?


Solution

  • In case anyone encounters a similar problem: In my case it was my antivirus (McAffe). Deactivating it solves the problem.