mattias1975
Programmer
Hello!
After the last fgets i get the message Segmentation fault from the operating system. What am i doing wrong?
(This is ofcaurse only a part of my application)
typedef struct mystruct
{
char a[10], b[10], c[10];
struct mystruct *link;
} mystruct;
struct mystruct* inputFunction()
{
struct mystruct *hello;
char *str;
str = malloc(100);
hello = (struct mystruct *)malloc(sizeof(struct mystruct));
printf("\na: ");
fgets(hello->a, 10, stdin);
printf("b: ");
fgets(hello->b, 10, stdin);
printf("c: ");
fgets(hello->c, 10, stdin);
free(hello);
free(str);
return hello;
}
After the last fgets i get the message Segmentation fault from the operating system. What am i doing wrong?
(This is ofcaurse only a part of my application)
typedef struct mystruct
{
char a[10], b[10], c[10];
struct mystruct *link;
} mystruct;
struct mystruct* inputFunction()
{
struct mystruct *hello;
char *str;
str = malloc(100);
hello = (struct mystruct *)malloc(sizeof(struct mystruct));
printf("\na: ");
fgets(hello->a, 10, stdin);
printf("b: ");
fgets(hello->b, 10, stdin);
printf("c: ");
fgets(hello->c, 10, stdin);
free(hello);
free(str);
return hello;
}