How to create an external character array in C?
I have tried various ways to define char cmdval[128]
but it always says undefined reference to 'cmdval'
I want to put a string in cmdval in first.c
file and use it in other second.c
file. I tried adding a global.h
file with extern char cmdval[128]
but no luck.
UPDATE:
global.h
extern char cmdval[128];
first.c
#include "global.h"
char cmdval[128];
function(){
strcpy(cmdval, "a string");
}
second.c
#include "global.h"
function(){
printf("%s \n",cmdval); //error
}
FAIL :( "undefined reference to `cmdval'"
EDIT: I am working in linux (editing a mini OS xv6 then compiling and running it in qemu), I don't know if it is a barrier