As part of my program, I have defined and initialized a structure. But when I compile it, gcc gives me the following error on all the initialization " initializer element is not constant". Anyone know why this is the case?
struct RECORD
{
char* username;
char* password;
char* type;
struct RECORD *next;
};
struct RECORD *head=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *temp=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *linktemp=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *pos=(struct RECORD*)malloc(sizeof(struct RECORD));
I get an error on code lines 9-12.
I tried this and it compiled no problems
#include <stdio.h>
#include <stdlib.h>
struct RECORD
{
char* username;
char* password;
char* type;
struct RECORD *next;
};
int main(int argc, char**argv)
{
struct RECORD *head=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *temp=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *linktemp=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *pos=(struct RECORD*)malloc(sizeof(struct RECORD));
exit(EXIT_SUCCESS);
}
Reputation Points: 499
Solved Threads: 367
Postaholic
Online 2,197 posts
since Jan 2008