Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define WOR_SIZ 15
- struct ksiazka{
- int id;
- char tytul[WOR_SIZ];
- char autor[WOR_SIZ];
- struct ksiazka *next;
- };
- void push(struct ksiazka **head, int id, char *tytul, char *autor){
- struct ksiazka *new_node=(struct ksiazka*)malloc(sizeof(struct ksiazka));
- if(new_node){
- new_node->id=id;
- strncpy(new_node->tytul,tytul,WOR_SIZ);
- strncpy(new_node->autor,autor,WOR_SIZ);
- new_node->next=(*head);
- (*head)=new_node;
- }
- }
- void pop(struct ksiazka **head){
- struct ksiazka *tmp=(*head);
- if(*head){
- (*head)=tmp->next;
- free(tmp);
- }
- }
- void wyswietl(struct ksiazka *head){
- struct ksiazka *p=head;
- while(p){
- printf("Id: %d\n", p->id);
- printf("Tytul: %s\n", p->tytul);
- printf("Autor: %s\n", p->autor);
- p=p->next;
- }
- }
- int main()
- {
- struct ksiazka *head=NULL;
- push(&head, 2, "abc", "J.Kowalski");
- wyswietl(head);
- pop(&head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement