daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Kolokwium zaliczeniowe.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #pragma warning (disable: 4996)
  9.  
  10. int main()
  11. {
  12.     Car * tab = (Car*)malloc(3 * sizeof(Car));
  13.    
  14.     printf("Podaj rok i nazwe samochodu");
  15.     for (int i = 0; i < 3; ++i)
  16.     {
  17.         CreateCar(&tab[i]);
  18.     }
  19.    
  20.     for (int i = 0; i < 3; ++i)
  21.     {
  22.         PrintCar(&tab[i]);
  23.     }
  24.     Car_Copy(&tab[1], &tab[2]);
  25.  
  26.     PrintCar(&tab[1]);
  27.    
  28.  
  29.     free(tab);
  30.     tab = NULL;
  31.  
  32.     system("pause");
  33.  
  34.     return 0;
  35. }
  36.  
  37.  
  38. void CreateCar(Car *tab)
  39. {
  40.     tab->name = (char*)malloc(64 * sizeof(char));
  41.  
  42.     scanf("%d%s", &tab->rok, tab->name);
  43. }
  44.  
  45. void PrintCar(Car *tab)
  46. {
  47.     printf("nazwa: %s, rok: %d", tab->name, tab->rok);
  48. }
  49.  
  50. void Car_Copy(Car *tab1, Car *tab2)
  51. {
  52.     if (tab1 && tab2)
  53.     {
  54.         Car * tabTemp = (Car*)malloc(sizeof(Car));
  55.         tabTemp->name = (char*)malloc(64 * sizeof(char));
  56.         tabTemp->name = tab1->name;
  57.         tabTemp->rok = tab1->rok;
  58.  
  59.         tab1->name = tab2->name;
  60.         tab1->rok = tab2->rok;
  61.         tab2->name = tabTemp->name;
  62.         tab2->rok = tabTemp->rok;
  63.  
  64.         free(tabTemp->name);
  65.         tabTemp->name = NULL;
  66.         free(tabTemp);
  67.         tabTemp = NULL;
  68.     }
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top