# Calling a function from another file [C]

Page 1 of 1

## 4 Replies - 3263 Views - Last Post: 07 October 2009 - 08:50 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=130374&amp;s=1557e21322db2024b73151dddb9a3ba0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 zefiend

Reputation: 0
• 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

• D.I.C Lover

Reputation: 291
• Posts: 1,900
• Joined: 25-October 06

## Re: Calling a function from another file [C]

Posted 06 October 2009 - 10:49 PM

zefiend, 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/

### #3 aks29921

• D.I.C Regular

Reputation: 86
• Posts: 254
• 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

### #4 jjl

• Engineer

Reputation: 1091
• Posts: 4,572
• Joined: 09-June 09

## Re: Calling a function from another file [C]

Posted 06 October 2009 - 11:42 PM

```
#pragma once;
class fun
{
{
return a+b;
}
};

```

```#include <iostream>

using namespace std;

int main()
{
fun x;

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

```

### #5 zefiend

Reputation: 0
• 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.