Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FUNCKJEEE
- #include "header.h"
- /*Tworzymy tablice*/
- int *create()
- {
- int *myarray;
- myarray = malloc(SIZE *sizeof(int));
- if (myarray == NULL){
- perror("malloc");
- exit(1);
- }
- return myarray;
- }
- void init(int* myarray, int n, int size) /* inicjalizowanie kazdego elementu tablicy na podana wartosc*/
- {
- int i;
- for(i=0; i< size; i++)
- {
- myarray[i] = n;
- }
- }
- int* enlargee(int* myarray)
- {
- int* wsk;
- wsk = malloc((SIZE + M ) * sizeof(int)); /* rezerwacja miejsca w pamieci dla powiekszonej tablicy*/
- if (wsk == NULL){
- perror("malloc");
- exit(0);
- }
- int i;
- for(i=0; i< (SIZE +M); i++)
- {
- if( i<SIZE)
- {
- wsk[i]= myarray[i]; /*zachowanie wartosci tablicy o rozmiarze SIZE*/
- }
- else
- {
- wsk[i]=0; /*komorki dodatkowe zdefiniowane przez M wypelnij zerem*/
- }
- }
- return wsk;
- }
- void setvalue(int* myarray, int n, int index, int value)/*n-romziar tablicy*/
- {
- if(index < n)
- {
- myarray[index]=value;
- }
- else
- {
- printf("Indeks wiekszy niz rozmiar tablicy");
- }
- }
- int readvalue(int* myarray , int n, int index)
- {
- if(index< n)
- {
- return myarray[index];
- }
- else
- {
- printf("Indeks wiekszy niz rozmiar tablicy");
- return -1;
- }
- }
- void removee(int* myarray)
- {
- free(myarray);
- }
- void show(int* myarray, int n)
- {
- int i;
- for(i=0; i< n; i++)
- {
- printf("myarray[%d]=% d\n", i,myarray[i]);
- }
- }
- HEADERRRRRRRR
- #include<stdio.h>
- #include<stdlib.h>
- #include <time.h>
- #define SIZE 5
- #define M 2
- int* create();
- void init(int* , int , int);
- int* enlargee(int* );
- void setvalue(int* , int , int , int);
- int readvalue(int* ,int , int );
- void removee(int* );
- void show(int* , int n);
- MAINNNNNN
- #include "header.h"
- #include "function.c"
- int main()
- {
- int* myarray;
- myarray = create();
- printf("Adres poczatku tablicy wynosi %p \n",create());
- /* wypelnianie utworzonej tablicy wartoscia 2*/
- init(myarray, 2, SIZE);
- show(myarray, SIZE);
- setvalue(myarray,SIZE, 2,5); /* ustawienie 3 elementu tablicy SIZE na wartosc 5*/
- show(myarray, SIZE);
- printf("%d element tablicy wynosi %d\n", 2+1, readvalue(myarray, (SIZE+M), 2));
- /*powiekszanie tablicy myarray*/
- myarray = enlargee(myarray);
- printf("Adres poczatku powiekszonej tablicy wynosi %p\n", enlargee(myarray));
- setvalue(myarray, (SIZE+M), 3, 10);
- show(myarray, (SIZE+M));
- init(myarray, 3, (SIZE+M)); /* ustawienie powiekszonej tablicy na wartosc 3*/
- show(myarray, (SIZE+M));
- setvalue(myarray, (SIZE+M), 4, 9); /* ustawia 5 element na wartosc 9*/
- printf("%d element tablicy wynosi %d\n", 4 +1 , readvalue(myarray, (SIZE+M), 4)); /* czyta 5 element z tablicy*/
- removee(myarray);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement