Hi!

I've tried to split it up a program I made for school into 3:
header.h: has the functions declarations.
func.c: contains the fundctions body.
body.c: uses the functoins.

Here's my code:

/* header.h */

void kelet(char *p);
void copy(char *p1,char *p2);
void insert(char *p1,char *p2);
void reverse(char *p1);
void length(char *p);
void pelet(char *p);
void compare(char *p1,char *p2);
void wordinword(char *p1,char *p2);
void print(char *p1,char *p2);
/* func.c */
#include<stdio.h>
#include<string.h>
#include "header.h"
void kelet(char *p)
{
 printf("Please enter string\n");
 scanf("%s",p);
}
void copy(char *p1,char *p2)
{
 while (*p2)
  *p1++=*p2++;
 *p1=*p2; // Copies the "/0" at the end
}
void insert(char *p1,char *p2)
{
 while (*p2++);
 p2--;
 while (*p1)
  *p2++=*p1++;
 *p2=*p1; // Copies the "/0" at the end
}

void reverse(char *p1)
{
  char *p2=p1;
  int temp,i,len;
  len=strlen(p1);
  while (*p2++);
  p2-=2;
  for (i=0;i<len/2;p1++,p2--,i++)
   {
 temp=*p1;
 *p1=*p2;
 *p2=temp;
   }
}
void length(char *p)
{
 int i;
 for (i=0;*p++;i++);
 printf("The length is %d",i);
}
void wordinword(char *p1,char *p2)
{
 char *p3,*p4;
 int count=0,len;
 len=strlen(p2);
 while(*(p1+len-1))
  {
   p3=p1;
   p4=p2;
   while(*p4 && *p4==*p3)
 {
  p4++;
  p3++;
 }
   if (*p4==0)
  count++;
   p1++;
  }
 printf("string2 apears %d times in string1",count);
}
void pelet(char *p)
{
 printf("%s",p);
}
void compare(char *p1,char *p2)
 {
  int value=0;
  while (*p1==*p2 && *p1 && *p2)
   {
 p1++;
 p2++;
   }
  value=*p1-*p2;
  if (value==0)
   printf("String1 == String2");
  else if (value<0)
   printf("String1 < String2");
  else
   printf("String2 < String1");
 }
void print(char *p1,char *p2)
{
 char *p3;
 int len,flag=0;
 len=strlen(p2);
 while (!flag)
  {
  p3=p2;
  while(*p3 && *p3==*p1)
 {
  p3++;
  p1++;
 }
   if (*p3==0)
 {
  p1=p1-len;
  flag=1;
 }
   else
 p1++;
   }
 printf("%s",p1);
}
/* body.c */
#include<stdio.h>
#include<conio.h>
#include "header.h"
#define N 100
void main()
{
 char string1[N],string2[N];
 int choice=0;
 clrscr();
 printf("Pick your choise from the following menu:\n");
 printf("1. Input string1\n2. Input string2\n3. Copy string2 into string1\n4. Insert string1 into string2\n");
 printf("5. Reverse string1\n6. Reverse string2\n7. Size of string1\n8. Size of string2\n");
 printf("9. Count string2 in string1\n10.Output string1\n11.Output string2\n12.Compare string1 and string2\n");
 printf("13.Find string2 in string1 and print the rest of string1\n14.Exit\n");
 scanf("%d",&choice);
 while (choice!=14)
 {
  switch(choice)
  {
   case 1: kelet(string1);
     printf("Thank you!");
     break;
   case 2: kelet(string2);
     printf("Thank you!");
     break;
   case 3: copy(string1,string2);
     printf("Done!");
     break;
   case 4: insert(string1,string2);
     printf("Done!");
     break;
   case 5: reverse(string1);
     printf("Done!");
     break;
   case 6: reverse(string2);
     printf("Done!");
     break;
   case 7: length(string1);
     break;
   case 8: length(string2);
     break;
   case 9: wordinword(string1,string2);
     break;
   case 10:pelet(string1);
     break;
   case 11:pelet(string2);
     break;
   case 12:compare(string1,string2);
     break;
   case 13:print(string1,string2);
     break;
   default:printf("The number you entered is invalid\n");
 }
  printf("\nPlease chose another option\n");
  scanf("%d",&choice);
 }//end of while
 printf("Thank you for taking part in our project");
 getch();
}

Pay no attention to what the program does.
I use Borland C++ V3.1.
When I try to either link or just Make (F9) one of the .c programs above I get the following error:
Unable to open include file "header.h"
I saved the header as .h format in the same folder as the other 2 files.

What can be the problem?

Thanks
Ami

You have included header.h twice (In both files). Use some sort code like of this (might be C++, sorry)

#ifndef HEADER
#define HEADER
#include "header.h"
#endif

But I dunno wether that is the real problem

OK figured it out...
The compiler needs the full path, eventhough all my files are in the same directory.

You have included header.h twice (In both files). Use some sort code like of this (might be C++, sorry)

#ifndef HEADER
#define HEADER
#include "header.h"
#endif

But I dunno wether that is the real problem

Its better in *.h file to do the protection

/**********
* header.h file
***********/
#ifndef HEADER_H
#define HEADER_H
/**** some func declarations ***/
#endif /* HEADER_H */

then in c file.

You have included header.h twice (In both files). Use some sort code like of this (might be C++, sorry)

#ifndef HEADER
#define HEADER
#include "header.h"
#endif

But I dunno wether that is the real problem

I don't see that problem at all. There is only one include in each .c file. And that would not cause a "can't find" error, that causes 'multiple definition' error.

Are you sure the files are all in the same directory? The " form of the include first looks in the current directory so the file should be found without a problem.

Yea all 3 files are in the same directory.
this is the code that DID work:

#include "e:\study\c\header.h"

Yea all 3 files are in the same directory.
this is the code that DID work:

#include "e:\study\c\header.h"

Then you have a problem with your installation or the way your project was set up. You shouldn't need to specify the path using the d-quote form of the #include

Yea I wouldn't be surprised. I'm using a DOS version of Borland C++. It doesnt even require installation just copying!!!

I'll take on Inanna's advice and try to get a new vrsion

Yea I wouldn't be surprised. I'm using a DOS version of Borland C++. It doesnt even require installation just copying!!!

I'll take on Inanna's advice and try to get a new vrsion

So am I, version 5.5, and it does require some minor installation. Here's how I do it

I would advise you to take an new compiler with build in editor like Dev-C++ or code::blocks.

I personally think it's way handy-er then the command prompt, and I never had problem's with header's in those.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.