How can i use read_vector
and display_vector
in C?
I have to shuffle array and then use this functions.
void shuffle(int tab[], int size)
.
I don't know if read_vector
and display_vector
is good.
Any help will be good.
(It have to be max 100 numebrs)
#include<stdio.h>
void shuffle(int tab[], int size);
int read_vector(int vec[], int size, int stop_value);
void display_vector(const int vec[], int size);
int main()
{
int i;
int tab[101], a;
printf("Podaj pierwszy wektor: ");
for(i=0; i<100; i++)
{
a = scanf("%d", &tab[i]);
if(a<1)
{
printf("Incorrect input");
return 1;
}
if(tab[0]==0)
{
printf("Not enough data available");
return 2;
}
if(tab[i]==0)
{
break;
}
}
shuffle(tab[i], i);
for(i=0; i<100; i++)
{
printf("%d", tab[i]);
}
return 0;
}
void shuffle(int tab[], int size)
{
int i, j=0, x=0;
for(i=size; i>0; i--)
{
j = rand() % size+1;
x = tab[i];
tab[i]=tab[j];
tab[j]=x;
x=0;
}
}