When I try to print an array contained in an instance of a struct part of the result is what I'm expecting and other parts seem to be gibberish. What is going on here?
Example output:
$./makevector test
NAME: test 16481592918288327671592918096327670000000000100011809530144490000159291832032767
My code is as follows:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
static int vec_length = 30;
typedef struct {
char* name;
int* vector;
} word_entry;
static word_entry entry_one = {NULL,NULL};
void MakeEntry(char* word, word_entry* entry){
entry->name = word;
int i;
int this_vector[vec_length];
srand(time(NULL));
for(i=0;i<vec_length;i++){
this_vector[i] = rand()%2;
}
entry->vector = this_vector;
}
int main(int argc, char* argv[]){
int i;
MakeEntry(argv[1], &entry_one);
printf("NAME: %s\n", entry_one.name);
for (i=0;i<vec_length;i++){
printf("%d",entry_one.vector[i]);
}
printf("\n");
}