How do I include a user defined header file in my project created in OnlineGDB?

–3 votes
asked May 5 by (180 points)
Ex. main.cpp, sample.h I created both and want to include sample.h in main.cpp

I tried putting it in " " - #include  "sample.h" and they are both in the same project but main.cpp couldn't find sample.h

1 Answer

0 votes
answered May 16 by (180 points)

Very simple. I will write for you a simple example.

main.c

#include <stdio.h>

#include "simple.h"

int main (void)  {

          printToken("hello everyone, i hope this help you");

          return (0);

}

simple.h

#pragma ONCE

// the header usually contains only prototypes or global variables

void printToken(char *string);

simple.c

#include <stdio.h>

#include "simple.h"

// this file contains the functions which "simple.h" reads from.

void printToken(char *string)  {

          printf("%s", string);

          return;

}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...