#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct lista {
char imie[20];
char nazwisko[20];
int wiek;
struct lista *next;
};
void dodaj(struct lista *dane) {
struct lista *tmp;
tmp=malloc(sizeof(struct lista));
char tmp1[20];
char tmp2[20];
printf("\n\nPodaj imie \n");
fgets(tmp1,20,stdin);
strcpy(tmp->imie, tmp1);
fflush(stdin);
printf("Podaj nazwisko \n");
fgets(tmp2,20,stdin);
strcpy(tmp->nazwisko, tmp2);
fflush(stdin);
printf("Podaj wiek \n");
scanf("%i",&tmp->wiek);
fflush(stdin);
tmp->next=NULL;
while(dane->next != NULL){
dane=dane->next;
}
dane->next=tmp;
}
void zapisz(struct lista *dane,FILE *plik){
plik=fopen("test.txt","w");
while(dane->next != NULL)
{
fprintf(plik,"\n%s",dane->imie);
fprintf(plik,"%s",dane->nazwisko);
fprintf(plik,"%i",dane->wiek);
dane=dane->next;
}
fprintf(plik,"\n%s",dane->imie);
fprintf(plik,"%s",dane->nazwisko);
fprintf(plik,"%i",dane->wiek);
fclose(plik);
}
void show(struct lista *dane)
{
while(dane->next != NULL)
{
printf("%s\n", dane->imie);
printf("%s\n", dane->nazwisko);
printf("%i\n", dane->wiek);
dane=dane->next;
}
printf("%s\n", dane->imie);
printf("%s\n", dane->nazwisko);
printf("%i\n", dane->wiek);
}
int main() {
FILE *pliczek;
struct lista *dane;
dane = malloc(sizeof(struct lista));
char znak;
strcpy(dane->imie,"Test");
strcpy(dane->nazwisko,"Testowe");
dane->wiek=20;
dane->next=NULL;
start:
printf("-------------------------------------------------------------\nCo chcesz zrobic?\n\n1. Dodaj nowy element\n2. Wypisz elementy\n3.Zapisz elementy do pliku\n4.Zakoncz program\n");
znak=getch();
if(znak=='1') {
fflush(stdin);
dodaj(dane);
goto start;
}
if(znak=='2') {
fflush(stdin);
show(dane);
goto start;
}
if(znak=='3') {
fflush(stdin);
zapisz(dane,pliczek);
goto start;
}
if(znak=='4')
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}