4 Replies - 2802 Views - Last Post: 07 October 2009 - 08:50 AM Rate Topic: -----

#1 zefiend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-February 09

Calling a function from another file [C]

Posted 06 October 2009 - 10:16 PM

Hello, I'm trying to call a function I've created in another file but I'm not really getting anywhere. Basically I'm calling it like so:

#include "file1.c"


What I want to do is call a function from file1.c in a function built into file2.c, is this possible?
Is This A Good Question/Topic? 0
  • +

Replies To: Calling a function from another file [C]

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Calling a function from another file [C]

Posted 06 October 2009 - 10:49 PM

View Postzefiend, on 7 Oct, 2009 - 04:16 AM, said:

Hello, I'm trying to call a function I've created in another file but I'm not really getting anywhere. Basically I'm calling it like so:

#include "file1.c"


What I want to do is call a function from file1.c in a function built into file2.c, is this possible?

have a look at
http://www.learncpp....multiple-files/
Was This Post Helpful? 0
  • +
  • -

#3 aks29921  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 84
  • View blog
  • Posts: 230
  • Joined: 24-August 09

Re: Calling a function from another file [C]

Posted 06 October 2009 - 10:53 PM

make file1.c a header file, i.e. save it as file1.h..
now include file1.h in your another file
Was This Post Helpful? 1
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Calling a function from another file [C]

Posted 06 October 2009 - 11:42 PM

create your header file

#pragma once;
class fun
{
   int add(int a, int b)
   { 
	   return a+b;
   }
};



call in your source file
#include <iostream>

using namespace std;

int main()
{
  fun x;
  cout<<x.add(1,2)<<endl;

  cin.get();
  cin.ignore();
  return 0;
}


Was This Post Helpful? 0
  • +
  • -

#5 zefiend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-February 09

Re: Calling a function from another file [C]

Posted 07 October 2009 - 08:50 AM

Okay, thanks for the help everyone.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1