Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Mateusz Buława */
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define MAX 20
- struct pilkarz {
- char nazwisko[40];
- char klub[40];
- float zarobki;
- struct pilkarz *next;
- };
- int main() {
- FILE * A;
- char wejscie[MAX];
- //otwarcie pliku
- printf("Podaj nazwe pliku z rozszerzeniem .txt: ");
- scanf("%s", &wejscie);
- A = fopen(wejscie, "r");
- //blad otwarcia pliku
- if (A == NULL) {
- printf("\nBlad otwarcia pliku.\n");
- fclose(A);
- return 0;
- }
- else
- printf("Plik wejsciowy zostal otwarty.\n");
- struct pilkarz * pel = NULL; //pierwszy element
- struct pilkarz * pom=NULL; //wskaznik na blok listy
- //tworzenie listy
- while (feof(A) == 0) {
- if (pel = NULL) {
- pel = pom = (struct pilkarz*)malloc(sizeof(struct pilkarz));
- }
- else {
- pom->next = (struct pilkarz*)malloc(sizeof(struct pilkarz));
- pom = pom->next;
- }
- //wczytanie z pliku do listy
- fscanf(A, "%s %s %f", &pom->nazwisko, &pom->klub, &pom->zarobki);
- //wypisanie w konsoli
- printf("Nazwisko pilkarza: %s, klub: %s, pensja: %.2f$", pom->nazwisko, pom->klub, pom->zarobki);
- pom->next = NULL;
- }
- //koniec programu
- fclose(A);
- pom = pel;
- while (pom != NULL) {
- pel = pom;
- pom = pel->next;
- free(pel);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement