L
lurch132002
i am trying to create an array of structs to hold some information but
whenever i get
to the second element and try to strncpy it i get a segmenation
fault. ive searched around for
similar problems but i cant seem to figure out what im doing wrong.
any help would be appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct filesys {
char *fname;
int cylinder;
int sector;
int length;
};
int main( int argc, char *argv[] ) {
struct filesys file_array[100];
int i;
for( i = 0; i < 100; i++ )
strncpy(file_array.fname, "hello", 6);
for(i = 0; i < 100; i++ )
printf("%s", file_array.fname);
}
whenever i get
to the second element and try to strncpy it i get a segmenation
fault. ive searched around for
similar problems but i cant seem to figure out what im doing wrong.
any help would be appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct filesys {
char *fname;
int cylinder;
int sector;
int length;
};
int main( int argc, char *argv[] ) {
struct filesys file_array[100];
int i;
for( i = 0; i < 100; i++ )
strncpy(file_array.fname, "hello", 6);
for(i = 0; i < 100; i++ )
printf("%s", file_array.fname);
}