c - Program crashes on line t->time = t0; -


i usiung mingw c programing environment, found serious problem. test code follows:

#include <time.h> #include <stdlib.h> #include <stdio.h>  typedef struct {        /* time struct */     time_t time;        /* time (s) expressed standard time_t */     double sec;         /* fraction of second under 1 s */ } gtime_t;  typedef struct {            gtime_t time;             int type;          } raw_t;  int main(){     raw_t *t;     gtime_t t0={0};     t->time = t0;     printf ("%d",(t->time).time);      return 0; } 

i defined 2 struct , 1 struct contained in other one. when run test program, crush on line

t->time = t0; 

can me on this?

t pointer has not been initialized. can't dereferenced assign value member. can either initialize heap

t = malloc(sizeof(raw_t)); 

or initialize stack

raw_t tonthestack; raw_t *t = &tonthestack; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -