Im getting a segmentation fault when I try to run the program and add new message. As soon as I input the 3 values it segfaults. Any help?
Code:
#include <stdio.h>
#include <string.h>
struct MSG {
int priority;
int destination;
char *message;
int length;
struct MSG *nextPtr;
};
typedef struct MSG Message;
int main ()
{
struct MSG {
int priority;
int destination;
char *message;
int length;
struct MSG *nextPtr;
};
struct MSG std[100];
int I;
int n;
int choice = 0;
do
{
printf("1.) Quit\n");
printf("2.) Transmit next message\n");
printf("3.) List messages by priority\n");
printf("4.) Summarize message list\n");
printf("5.) Add new message\n");
printf(":");
scanf("%d", &choice);
switch(choice)
{
case 1:
return 0;
case 2:
//transmit next message
break;
case 3:
//list messages by priority
break;
case 4:
//summarize message list
break;
case 5:
//add new message
printf("How many messages would you like to enter?\n");
scanf("%d", &n);
printf("Enter a priority, destination, and message:");
for (I=0; I < n; I++)
{
scanf("%d%d%s", &std[I].priority, &std[I].destination, &std[I].message);
}
printf("\ntest info:");
for (I=0; I < n; I++)
{
printf("%d%d%s\n", std[I].priority, std[I].destination, std[I].message);
}
break;
default:
printf("Invalid entry, please try again.\n");
break;
}
}while (choice <= 5);
return 0;
}