I am defining structure using separate unit which is first.c, and then looking to access it in my main module by using function call processSructFromMain. But only direct call to printf is worked. Call to processStructFromMain simply does not produce results at all. "Struct2 " in second printf does not show results as well.
What I am doing wrong ?
All of the in c, 11 standard
main:
#include <stdio.h>
#include <stdlib.h>
#include "first.h"
void processStructFromMain(myStruct *s){
printf("anotherProcess %s \n", s->name);
}
int main() {
myStruct* s = getStructFromFirst();
printf("Struct1 %s \n", s->name);
processStructFromMain(s);
printf("Struct2 %s \n", s->name);
return 0;
}
first.c
#include "first.h"
myStruct *getStructFromFirst() {
char* chr = "THIS IS STRING \0";
myStruct* s = &(myStruct){.name=chr};
return s;
}
first.h
#ifndef TESTONE_FIRST_H
#define TESTONE_FIRST_H
struct MYSTRUCT{
char* name;
};
typedef struct MYSTRUCT myStruct;
myStruct* getStructFromFirst();
#endif //TESTONE_FIRST_H