sorry for bad english and an incorrect form. im trying to make linked list in c im my code, i want to break loop when i input -1,0,0 it break anyway, but i have to press other key to break
how can i break directly without press additional key?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "account.h"
int main()
{
int id=0,balance=0;
char name[20];
struct account *p, *head = NULL;
printf("%-9s %8s %-4s\n", "id", "name", "balance");
while (1)
{
scanf("%d %s %d\n", &id, name, &balance);
p = (struct account*)malloc(sizeof(struct account));
if (p == NULL) {
perror("malloc");
exit(1);
}
if(id ==-1)
break;
else{
p->id = id;
strcpy(p->name, name);
p->balance = balance;
p->next = head;
head = p;
}
}
printf("reverse account\n");
p = head;
while (p != NULL) {
printf("id %d name %s balance %d \n", p->id, p->name,p->balance);
p = p->next;
}
return 0;
}
i changed line 21 position up and down but it doesn't work