I want to take string input from user and store it in a structure's pointer variable. The following code works fine in TurboC3 compiler, but fails in MinGW / VSCODE
#include<stdio.h>
typedef struct telephone
{
char *name;
int number;
}bullettrain;
int main() {
bullettrain t[3];
int i, num;
for(i=0; i<=2; i++) {
printf("Enter Your Name: ");
gets(t[i].name);
printf("Enter your Number: ");
scanf("%d", &num);
t[i].number = num;
fflush(stdin);
}
for(i=0; i<=2; i++) {
printf("Name: %s", t[i].name);
printf("\nNumber: %d", t[i].number);
printf("\n-------------------------\n");
}
return 0;
}
How to make it work in MinGW / VSCODE?