Guest User

Untitled

a guest
Jan 10th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string>
  4.  
  5. typedef struct nod {
  6. char titlu[25];
  7. char autor[20];
  8. char editura[20];
  9. nod *next;
  10. }NOD;
  11.  
  12. NOD *head = (NOD*)malloc(sizeof(NOD));
  13. NOD *nodc;
  14.  
  15. void citire(int n) {
  16. nodc = head;
  17. for (int i = 0; i < n; i++) {
  18. printf("Titlu: ");
  19. scanf("%s", &nodc->titlu);
  20. printf("Autor: ");
  21. scanf("%s", &nodc->autor);
  22. printf("Editura: ");
  23. scanf("%s", &nodc->editura);
  24. nodc->next = (NOD*)malloc(sizeof(NOD));
  25. nodc = nodc->next;
  26. nodc->next = NULL;
  27. }
  28. }
  29.  
  30. void afisare() {
  31. nodc = head;
  32. char aux[10] = "Teora";
  33.  
  34. while (nodc->next) {
  35. if (strcmp(nodc->editura, aux)==0) {
  36. printf("Titlu: %s\n", nodc->titlu);
  37. printf("Autor: %s\n", nodc->autor);
  38. printf("Editura: %s\n", nodc->editura);
  39. }
  40. nodc = nodc->next;
  41. }
  42. }
  43.  
  44. int main() {
  45. int n;
  46.  
  47. printf("Cate carti adaugati?\nn= ");
  48. scanf("%d", &n);
  49. citire(n);
  50. afisare();
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment