Here is Define.c
#include "Define.h"
// this line working
// Format date_format = { "YYMMDD", "%02u%02u%02u", 6, 3 }; // line1
Format date_format;
// this line are now working
strcpy(date_format.format, "YYMMDD"); // line2
strcpy(date_format.scanformat, "%02u%02u%02u"); // line3
date_format.scansize = 3; // line4
date_format.printsize = 6; // line5
Here is Define.h
#ifndef _DEFINE_H
#define _DEFINE_H
typedef struct Format
{
char format[256];
char scanformat[256];
unsigned int printsize;
unsigned int scansize;
} Format;
extern Format date_format;
#endif
main.c
#include <stdio.h>
#include "Define.h"
int main(int argc, char* argv[])
{
printf(date_format.format);
getchar();
return 0;
}
My question is why second definition in line no. 2/3/4/5 is not working? It is all I want with this struct initialization/definition/assignment. OR it must be contained within a method, but if so then why line1 is working correctly? I am using Visual Studio 2017