Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Svet.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- tSvet *vytvorSvet(char *nazev, int cislo, char *zprava, char **poleSouhvezdi){
- tSvet *svet;
- svet = (tSvet*)malloc(sizeof(tSvet));
- fflush(stdin);
- svet->poleSouhvezdi = (char**)malloc(5 * sizeof(char*));
- for (int i = 0; i < 5; i++)
- {
- svet->poleSouhvezdi[i] = (char*)malloc(20 * sizeof(char));
- }
- svet->zprava = (char*)malloc(256 * sizeof(char));
- strcpy(svet->nazevSveta, nazev);
- svet->cisloSveta = cislo;
- strcpy(svet->zprava, zprava);
- for (int i = 0; i < 5; i++)
- {
- strcpy(svet->poleSouhvezdi[i], poleSouhvezdi[i]);
- }
- svet->next = NULL;
- return svet;
- }
- int main(int argc, char* argv[]){
- char **poleSouhvezdi;
- poleSouhvezdi = (char**)malloc(5 * sizeof(char*));
- for (int i = 0; i < 5; i++)
- {
- poleSouhvezdi[i] = (char*)malloc(20 * sizeof(char));
- }
- for (int i = 0; i < 5; i++)
- {
- printf("Zadejte #%d souhvezdi: \n", i + 1);
- gets(poleSouhvezdi[i]);
- }
- /*for (int i = 0; i < 5; i++)
- {
- printf("#%d = %s\n", i + 1, poleSouhvezdi[i]);
- }*/
- tSvet *svet = vytvorSvet("Nazev", 1, "Zprava", poleSouhvezdi);
- printf("%s\n", svet->zprava);
- system("pause");
- return 0;
- }
- void zrusSvet(tSvet *svet){
- free(svet->nazevSveta);
- free(svet->zprava);
- for (int i = 0; i < 5; i++)
- {
- free(svet->poleSouhvezdi[i]);
- }
- free(svet);
- svet = NULL;
- }
- tSvet *vytvorKopii(tSvet *svet);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement