Hi..
I'm trying to write a simple program to include a c file in another one..
TEST1.c
#include<stdio.h>
#include<conio.h>
#include<test.c>
void main()
{
printf("%c" str);
getch();
}

test.c
#include<stdio.h>
#include<conio.h>
extern char str;
void main()
{
str='A';
}


Is somethin like this is possible??? Code didn't run successfully

Recommended Answers

All 2 Replies

You'd have multiple definitions of main, which is an error.

A few other points:
- main's return type should be int.
- you should never include .c files. The compiler will create object files (.o or .obj, possibly others depending) and then the linker will put the pieces together. However, functions and structs should be declared (but not necessarily defined) in .h files, which you should #include as needed.
- Try to avoid using conio.h and the functions therein. They are not available with most compilers and hence other people cannot run your code as is. Look into input methods with the standard I/O libraries.

Thanks for ur reply....

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.