The program I have made has few issues.
Main issue is when I try to scan a string entry, program crashes. I can't understand where is the problem and I don't know how to solve it. Integer part works fine but string elements seems to have some problems.
How I can manage and fix that problem? I have checked several topics about it but I still could not understand, can someone show me by changing mistaken lines of my code?
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#pragma warning(disable:4996)
struct flight {
int number;
char source[20];
char destination[20];
struct flight* next;
};
void enter();
void display();
void delete();
int count();
typedef struct flight NODE;
NODE* head_node, * first_node, * temp_node = 0, * prev_node, next_node;
int data;
char data2[20], data3[20];
struct flight f[];
void enter()
{
printf("\nEnter flight number: \n");
scanf("%d", &data);
printf("\nEnter flight source: \n");
scanf(" %s", &data2);
printf("\nEnter flight destination: \n");
scanf(" %s", &data3);
temp_node = (NODE*)malloc(sizeof(NODE));
temp_node->number = data;
temp_node->source = data2[20];
temp_node->destination = data3[20];
if (first_node == 0)
{
first_node = temp_node;
}
else
{
head_node->next = temp_node;
}
temp_node->next = 0;
head_node = temp_node;
fflush(stdin);
}