0

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.

Niranjan Sonachalam
  • 1,545
  • 1
  • 20
  • 29

2 Answers2

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.

Community
  • 1
  • 1
cnicutar
  • 178,505
  • 25
  • 365
  • 392