So I am trying to practice creating linked list. I run into a bug immediately using scanf. I am using a printf statement followed by a scanf but it seems to be working backwards. Like the printf s will not run until after scanf. Which is really weird to me.
#include<stdio.h>
//linked list node
typedef struct myList {
int info; //data info
struct mylist *link; //self reference link
}Node;
int main()
{
printf("Starting\n");
Node *a = (Node*)malloc(sizeof(Node));
Node *b = (Node*)malloc(sizeof(Node));
Node *c = (Node*)malloc(sizeof(Node));
a ->link = NULL;
b ->link = NULL;
c ->link = NULL;
//this section is working backwards
printf("a data = ?");
scanf("%d", &a->info);
putchar('\n');
return 0;
}
terminal output:
1(input 1 here)
Starting
a data = ?
Starting and a data =?, should be printing 1st??
#include<stdio.h>
//linked list node
typedef struct myList {
int info; //data info
struct mylist *link; //self reference link
}Node;
int main()
{
printf("Starting\n");
Node *a = (Node*)malloc(sizeof(Node));
Node *b = (Node*)malloc(sizeof(Node));
Node *c = (Node*)malloc(sizeof(Node));
a ->link = NULL;
b ->link = NULL;
c ->link = NULL;
//this section is working backwards
printf("a data = ?");
scanf("%d", &a->info);
putchar('\n');
return 0;
}
terminal output:
1(input 1 here)
Starting
a data = ?
Starting and a data =?, should be printing 1st??