The essence of the question is as follows. It is necessary to add structure to the list. But an error pops up: void push(avia *,int,char *,char *) : it is not possible to convert argument 1 from avia ** to avia * . I do not understand what's wrong.

Here is the case:

 if (uslovie == true) { int number; char destination[10]; char time[10]; printf("Vvedite nomer: "); scanf_s("%d", &number); printf("\n"); printf("Vvedite punkt: "); gets_s(destination); printf("\n"); printf("Vvedite vremya: "); gets_s(time); printf("\n"); system("cls"); push(&head, number, destination, time); printf("Element uspeshno dobavlen!\n"); system("pause"); break; } else printf("Sozdaite spisok!\n"); system("pause"); break; 

But the called function:

 void push(avia **head, int number, char *destination, char *time) { avia *tmp = (avia*)malloc(sizeof(avia)); if (*head == NULL) { tmp->number = number; for (int i = 0; i < 10; i++) tmp->destination[i] = destination[i]; for (int i = 0; i < 10; i++) tmp->time[i] = time[i]; tmp->next = NULL; *head = tmp; } else { tmp->number = number; for (int i = 0; i < 10; i++) tmp->destination[i] = destination[i]; for (int i = 0; i < 10; i++) tmp->time[i] = time[i]; tmp->next = *head; *head = tmp; } } 
  • And there is no necessary piece in the question ... - Qwertiy
  • @Qwertiy and what is needed? initialization? - corpsolovei
  • You obviously deceive us. The code is not compiled primarily because the get_s function get_s two parameters, not one. And this error will be reported by the compiler before the push call. The same error that you cited cannot be explained by the code given so far. - AnT
  • 2
    @VladfromMoscow, why this bundle of dubious tags? - Qwertiy
  • one
    @AnT, there are telepaths :) - Qwertiy

1 answer 1

You have parameters in the preliminary declaration of the function and the parameters in its definition do not match each other.

The function is declared as

 void push(avia *,int,char *,char *): ^^^^^^ 

While in its definition the first parameter has a different type.

 void push(avia **head, int number, char *destination, char *time) ^^^^^^^^^^^ { //... 

there is obviously a typo in the pre-declaration function. It must be declared as well as in the definition.

In addition, in the definition of a function, the code is duplicated, and the strings, if you are dealing specifically with strings as values ​​of structure fields, are incorrectly copied.

The function definition might look like this.

 void push(avia **head, int number, char *destination, char *time) { avia *tmp = (avia*)malloc(sizeof(avia)); if ( tmp != NULL ) { tmp->number = number; strncpy( tmp->destination, destination, 10 ); tmp->destination[9] = '\0'; strncpy( tmp->time, time, 10 ); tmp->time[9] = '\0'; tmp->next = *head; *head = tmp; } } 

It will be even better if the function is declared as

 void push(avia **head, int number, const char *destination, const char *time); ^^^^^ ^^^^^^ 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nofate