In input(), system("clear") executes first in a while loop, and then add(); is called... however, before add(); finishes and returns to input(), system("clear"); is called again and executes in the middle of add();
Code:
while (continu==1){
system("clear");
printf("\n\nEnter Command: ");
fgets(input, sizeof(input), stdin);
if ((p = strchr(input, '\n')) != NULL)
*p = '\0';
if (strcmp(input, "a")==0){add();}
}
Here is add();
Code:
void add(){
char input[250];
char *p;
List *new=(List *)malloc(sizeof(List));
printf("\n\nEnter Name: ");
fgets(input, 250, stdin);
if ((p = strchr(input, '\n')) != NULL)
*p = '\0';
strcpy(new->name, input);
printf("Name: %s", new->name);
printf("\n\nEnter Number: ");
fgets(input, sizeof(input), stdin);
if ((p = strchr(input, '\n')) != NULL)
*p = '\0';
strcpy(new->number, input); <--------- Why would system("clear") execute here??????
printf("Number: %s", new->number);
}
When I run the program, system("clear"); executes a second time, right before the final line of add(); such that the screen is cleared prematurely, and then the final printf statement is executed, followed by the "Enter Command" from input();