Why this c-program gives error when I initialize structure members (user.username and user.pin) outside the main function?, But everything becomes fine when I initialize it inside the main function.
Also is there any way to initialize a char array (member of structure)?
#include <stdio.h>
typedef struct {
int pin;
char username[20];
} portal;
portal user;
// user.username = "alex";
// user.pin[20] = 1234; //Why this gives error when I intialize it here(i.e outside the main function)?
int main() {
user.username = "alex"; //How to intialize a memeber(having type char) of structure?
user.pin[20] = 1234;
printf("WELCOME TO PORTAL\n");
printf("ENTER YOUR USERNAME:\n");
scanf("%[^\n]%*c", user.username);
.
.
.
Actually I'm getting this output when I initialize user.username outside the main function.
