Header #1 city.h
Code:
typedefstructCity{
double* lat;
double* lon;
double* pop;
char* airport;
char* name;
}City;
Header #2 vector.h
Code:
Header file #2 "vector.h"
typedefstructVector{
City* cityArray[26];// 26 pointers to struct City
}Vector;
C file
Code:
#include"vector.h"
#include"city.h"
#include<stdlib.h>
int main() {
Vector *cities;
init(cities); //calls function init
void init(Vector*ptr){
ptr->cityArray[0]->name ="hi";// Error Seg Fault! ptr = (Vector*) NULL
}
Earlier, I was able to compile and print out "hi" no problems. Now
all of a sudden, I'm getting seg faults each time. I'm 100% sure I'm running
the same code.
Whats going on? Is it because in city.h char* name is not initialized? I can't
initialize it, the compiler gives me an error when i try.