Well, I want to pass a string value from one file to another, how do I do that ? I don't want to save it to a text file and read it in the other one, I directly want to pass it to another c file .Thanks in advance.
Asked
Active
Viewed 309 times
0
-
2Like a function call? A definition? Copy and paste in the editor? – forsvarir Oct 13 '11 at 07:08
2 Answers
1
maybe just a #define MY_STR "your value" will do the job.
just create a .h file and include in both your C files
#ifndef _MY_HEADER_H
#define _MY_HEADER_H
#define MY_STR "your value"
#endif
then in your sources
#include "yourfile.h"
and use your MY_STR as a constant (please note that MY_STR will be a macro)

BigMike
- 6,683
- 1
- 23
- 24
0
You probably want an extern char commonstr[]
somewhere at the top (possibly in a header?) and a char commonstr[LENGTH]
in one of the .c
files. Then commonstr
will be available throughout your project.
There is an awesome post about extern variables in C.