Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void psn(lst *head, FILE *fp) //b)
- {
- if (head == NULL)
- {
- printf("The list is empty");
- return;
- }
- int err = 0;
- while (head != NULL)
- {
- if (err = fprintf(fp, "%s\n", head->data.name) != 1)
- printf("Greshka pri zapis\n");
- if (err = fprintf(fp, "%d\n", head->data.num) != 1)
- printf("Greshka pri zapis\n");
- if (err = fprintf(fp, "%f\n", head->data.cht) != 1)
- printf("Greshka pri zapis\n");
- head = head->next;
- }
- if (fp)
- fclose(fp);
- }
- int ct(lst *head) //в)
- {
- if (head == NULL)
- {
- printf("The list is empty");
- return;
- }
- int countOfNode = 0;
- while (head != NULL)
- {
- if (head->data.num < 10)
- {
- countOfNode++;
- }
- head = head->next;
- }
- return countOfNode;
- }
- int main()
- {
- lst *head = NULL;
- int countNodes;
- countNodes = ct(head);
- printf("Broq na vuzlite: %d", countNodes);
- char fileName[64];
- printf("Vuvedete ime na faila za zapis: ");
- scanf("%63s", fileName);
- FILE *fp = fopen(fileName, "wt");
- if (fp == NULL)
- {
- printf("Greshka pri otvarqne");
- return;
- }
- psn(head, fp); //записваме списъка във файл
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment