Been working on this for 3 days and no progress, I'm still new to C.
What I'm trying to do is after getting data and stored into the struct RiderInfo.
void ridertopsort() is sorting based on the time.
void gettop() is to read what the racelength is and then store the data into tb struct. For now I'm trying to just figure out how to store the name only.
the 2nd and 3rd else if statement are bit different because I tried both ways in trying to copy name from Riderinfo to tb.
I'm not sure what I'm getting wrong, I can run the code but it exits directly without giving me any results and I know the problem is within the gettop() function.
struct shorrt
{
char topname[3][81];
int topagegroups[3];
int tophrs[3];
int topmin[3];
char botname[3][81];
int botagegroups[3];
int bothrs[3];
int botmins[3];
};
struct medium
{
char topname[3][81];
int topagegroups[3];
int tophrs[3];
int topmin[3];
char botname[3][81];
int botagegroups[3];
int bothrs[3];
int botmins[3];
};
struct lonng
{
char topname[3][81];
int topagegroups[3];
int tophrs[3];
int topmin[3];
char botname[3][81];
int botagegroups[3];
int bothrs[3];
int botmins[3];
};
struct tb
{
struct shorrt sr;
struct medium mr;
struct lonng lr;
};
struct RiderInfo
{
char name[81];
int age;
char raceLength;
int startTime;
int mountainTime;
int finishTime;
int withdrawn;
};
void ridertopsort(struct RiderInfo info[])
{
int i, j;
struct RiderInfo sorttemp;
for (i = 0; i < 5000; i++) {
for (j = i + 1; j < 5000; j++) {
if ((info[j].finishTime - info[j].startTime) < (info[i].finishTime - info[i].startTime))
{
sorttemp = info[j];
info[j] = info[i];
info[i] = sorttemp;
}
}
}
}
void gettop(struct RiderInfo info[], struct tb topbtm[])
{
int a,i,j,k,m;
m = 0;
i = 0;
a = type();
while(m == 0)
{
if (a == 1 && (info[i].raceLength == 's') || (info[i].raceLength == 'S'))
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 81; k++)
{
strcpy(info[i].name, topbtm->sr.topname);
if (j == 2)
{
m = 1;
}
}
}
}
else if (a == 2 && (info[i].raceLength == 'm') || (info[i].raceLength == 'M'))
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 81; k++)
{
strcpy(info[i].name, topbtm->mr.topname);
if (j == 2)
{
m = 1;
}
}
}
}
else if (a == 2 && (info[i].raceLength == 'l') || (info[i].raceLength == 'L'))
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 81; k++)
{
strcpy(info[i].name[k], topbtm->lr.topname[j][k]);
if (j == 2)
{
m = 1;
}
}
}
}
i++;
}
}
You need to address the fields of the instances of your structure, or use memcpy(). For example, when you write,
void ridertopsort(struct RiderInfo info[])
{
struct RiderInfo sorttemp;
// ...
You either can copy each field, with something like
memcpy(&sorttemp.name, &info[j].name, sizeof(sorttemp.name));
sorttemp.age = info[j].age;
// ...
Or copy the entire structure, with
memcpy(&sorttemp, &info[j], sizeof(sorttemp));
Also consider whether you really want three identical struct declarations. if you really, truly want to keep that, you probably want to code defensively, with a few lines such as,
static_assert( sizeof(sorttemp) == sizeof(info[0]), "" );
This will at least protect you from changing the size of one of your structures in a way that breaks existing code, although not from breaking layout compatibility while leaving the size the same.
Related
How can I cycle through the array using a for loop and the reference operator?
for (i = 0; i < university->size; i++)
{
if (university->arr->MarkA <= 100)
{
sum += university->arr->MarkA;
count++;
}
Where should I insert the i?
These are the structures:
typedef struct Student
{
char *name;
long ID;
int MarkA, MarkB, HW;
}stud;
typedef struct University
{
stud *arr;
int size;
}Uni;
I used a function to create a University array
void build_Uni(FILE* in, Uni* university)
{
int i = 0;
stud temp;
char Name[100];
while (!feof(in))
{
fscanf(in, "%s%li%d%d%d", Name, &temp.ID, &temp.MarkA, &temp.MarkB, &temp.HW);
i++;
}
university->size = i;
rewind(in);
university->arr = (stud*)malloc(university->size * sizeof(stud));
if (university->arr == NULL) Get_Lost("Memory allocation failed!");
else for (i = 0; i < university->size; i++)
fill_Uni(in, university->arr + i);
}
void fill_Uni(FILE* in, stud* student)
{
char Name[100];
fscanf(in, "%s%li%d%d%d", Name, &student->ID, &student->MarkA, &student->MarkB, &student->HW);
student->name = (char*)malloc((strlen(Name) + 1) * sizeof(char));
if (student->name == NULL) Get_Lost("Error allocatig memory");
strcpy(student->name, Name);
}
In the main function I called the above functions to work on this structure
Uni university;
How can I cycle through the array using a for loop and the reference
operator?
I think you mean the dereference operator -> but referencing and dereferencing will have nothing to do with cycling through the array; that's what your for-loop is for.
Where should I insert the i?
This:
for (i = 0; i < university->size; i++)
{
if (university->arr->MarkA <= 100)
{
sum += university->arr->MarkA;
count++;
}
}
Should be this:
for (i = 0; i < university->size; i++)
{
if (university->arr[i].MarkA <= 100)
{
sum += university->arr[i].MarkA;
count++;
}
}
Concerning your original question, you should access it as follows:
University university;
...
for (i = 0; i < university.size; i++) {
if (university.arr[i].MarkA <= 100)
{
sum += university.arr[i].MarkA;
count++;
}
...
}
If university is of type University*, however, the code changes a little bit, since you then have to use operator -> to access the university-members:
for (i = 0; i < university->size; i++) {
if (university->arr[i].MarkA <= 100)
{
sum += university->arr[i].MarkA;
count++;
}
...
}
I have to implement a priority queue using binary heap in C for the university assignment. Program should get the n values from input, when value is 0, it should print the ID number(so, if task that was added as 5th element has the highest priority 7, print "5") and remove the highest-priority task from queue, and when value>0 it should add new node. To implement ID's and priority, I used arrays of structs.
The task would be quite simple, if not the fact that it should also print lower ID's if the priority of elements are the same...
I've done my research, but the only advice that I've managed to found is to modify the fragments of typical heap functions (insertkey, heapify) to also look for elements' ID. I've tried to do this, but I have no idea what went wrong - elements are still not sorted in the way I want them to be. I would be grateful for any piece of advice and tips!
Code:
#include <stdio.h>
#define SIZE 99999
int heapsize = 0;
int count = 0;
struct pqueue
{
int priority;
int id;
};
struct pqueue A[SIZE];
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
void initializearray()
{
for(int i=0; i<SIZE; i++)
{
A[i].priority = 0;
A[i].id = 0;
}
}
void printheap(); //prototype of debugging function
int left(int i)
{
return (i * 2) + 1;
}
int right(int i)
{
return (i * 2) + 2;
}
int parent(int i)
{
return ((i - 1) / 2);
}
void insertkey(int z)
{
heapsize++;
int i = heapsize - 1;
A[i].priority = z;
count++;
A[i].id = count;
while (i != 0 && A[parent(i)].priority < A[i].priority)
{
swap(&A[i].priority, &A[parent(i)].priority);
swap(&A[i].id, &A[parent(i)].id);
i = parent(i);
}
i = heapsize-1;
while(i != 0 && A[parent(i)].priority == A[i].priority && A[parent(i)].id > A[i].id )
{
swap(&A[i].priority, &A[parent(i)].priority);
swap(&A[i].id, &A[parent(i)].id);
i = parent(i);
}
// printheap();
}
void maxheapify(int i)
{
int l = left(i);
int r = right(i);
int largest;
if (l <= heapsize && A[l].priority >= A[i].priority)
{
largest = l;
if(A[l].priority == A[i].priority)
{
if(A[l].id < A[i].id)
{
largest = l;
}
else
{
largest = i;
}
}
}
else
{
largest = i;
}
if (r <= heapsize && A[r].priority >= A[largest].priority)
{
largest = r;
if(A[r].priority == A[largest].priority)
{
if(A[r].id < A[largest].id)
{
largest = r;
}
}
}
if (largest != i)
{
swap(&A[i].priority, &A[largest].priority);
swap(&A[i].id, &A[largest].id);
maxheapify(largest);
}
}
int extractmax()
{
int max = A[0].id;
A[0].priority = A[heapsize-1].priority;
A[0].id = A[heapsize-1].id;
heapsize--;
//printheap();
maxheapify(0);
return max;
}
void printheap() // debug function
{
for(int i = 0; i < heapsize; i++)
{
printf("prio %d id %d \n", A[i].priority, A[i].id);
}
}
int main()
{
int n;
int z;
initializearray();
scanf("%d", &n);
for(int i=0; i<n; i++)
{
scanf("%d", &z);
if(z != 0)
{
insertkey(z);
}
else
{
int local = extractmax();
if(local != 0 && heapsize+1 != 0)
{
printf("%d\n", local);
// printheap();
}
}
}
return 0;
}
Example input:
7
3 0 0 2 8 8 0
Output:
1
3
Example input (here comes the problem:)
10
1 1 1 1 2 0 0 0 0 0
Output:
5
3
2
4
1
Expected output:
5
1
2
3
4
Thank you for your time!
Instead of incorporating the logic directly into the heap implementation, write a comparison function that considers the id if the priorities are the same:
int pqless(const struct pqueue *a, const struct pqueue *b)
{
if (a->priority < b->priority) return 1;
if (a->priority > b->priority) return 0;
return (a->id > b->id);
}
This function returns true if a's priority is less than b's. If both priorities are equal, it returns true if a's id is smaller than b's.
Now update your heap code. Wherever you compare the priorities in the original code, now just call the function:
void insertkey(int z)
{
int i = heapsize++;
A[i].priority = z;
A[i].id = ++count;
while (i != 0 && pqless(&A[parent(i)], &A[i])) {
swap(&A[i].priority, &A[parent(i)].priority);
swap(&A[i].id, &A[parent(i)].id);
i = parent(i);
}
}
void maxheapify(int i)
{
int l = left(i);
int r = right(i);
int largest = i;
if (l <= heapsize && !pqless(&A[l], &A[i])) largest = l;
if (r <= heapsize && !pqless(&A[r], &A[largest]))largest = r;
if (largest != i) {
swap(&A[i].priority, &A[largest].priority);
swap(&A[i].id, &A[largest].id);
maxheapify(largest);
}
}
I'm trying to write Conway's game of life in C. This is what I have so far. I'm using pointers to refer to the arrays, which has never caused me problems before, but the function place_cell is causing a segfault.
Here's what I've tried so far:
- I tried making the grid with constants, 100 x 100, and 10 x 10. Modifying
values inside of those constant grids still gives me a segfault.
- I tried using constants for place_cell, still got a segfault.
int** make_grid(int x, int y) {
int** is = (int**)malloc(sizeof(int*) * y);
if(! is) {
fprintf(stderr, "make_grid: malloc failed");
exit(1);
}
int j;
for(j = 0; j < y; j++) {
is[j] = (int*)malloc(sizeof(int) * x);
if(!is[j]) {
fprintf(stderr, "make_grid: malloc failed");
exit(1);
}
}
return is;
}
/* takes two integers and places a cell at those coords */
void place_cell(int** is, int sidex, int sidey, int x, int y) {
if(x >= sidex || y >= sidey) {
fprintf(stderr, "place_cell: out of grid range\n");
exit(1);
}
is[y][x] = 1;
}
int check_surroundings(int** is, int sidex,
int sidey, int x, int y) {
int y_less = y - 1;
if(y == 0) {
y_less = sidey - 1;
}
int y_more = y + 1;
if(y == sidey - 1) {
y_more = 0;
}
int x_less = x - 1;
if(x == 0) {
x_less = sidex - 1;
}
int x_more = x + 1;
if(x == sidex - 1) {
x_more = 0;
}
int p = is[y_less][x_less] +
is[y_less][x] +
is[y_less][x_more] +
is[y][x_less] +
is[y][x_more] +
is[y_more][x_less] +
is[y_more][x_less] +
is[y_more][x_more];
return p;
}
void change_condition(int** is,
int sidex, int sidey, int x, int y) {
int* state = &is[y][x];
int surr = check_surroundings(is, sidex, sidey, x, y);
if(surr > 3) {
*state = 0;
} else if(surr == 3 || surr == 2) {
*state = 1;
} else {
*state = 0;
}
}
void print_grid(int** is, int sidex, int sidey) {
int i, j;
for(i = 0; i < sidey; i++) {
for(j = 0; j < sidex; j++) {
if(is[i][j] == 1) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
}
void new_generation(int** is, int sidex, int sidey) {
int i, j;
for(i = 0; i < sidey; i++) {
for(j = 0; j < sidex; j++) {
change_condition(is, sidex, sidey, j, i);
}
}
}
void play(int** is, int sidex, int sidey) {
int i = 0;
while(i < 100) {
new_generation(is, sidex, sidey);
print_grid(is, sidex, sidey);
i++;
}
}
here's my main:
int main(int argc, char* argv[]) {
int sidex = atoi(argv[0]);
int sidey = atoi(argv[1]);
int** is = make_grid(10, 10);
int i;
for(i = 2; i < argc; i += 2) {
place_cell(is, sidex, sidey,
atoi(argv[i]), atoi(argv[i + 1]));
}
return 0;
}
edit:
int** make_grid(int x, int y) {
int (*is)[x] = (int*)malloc(sizeof(int) * y * x);
if(! is) {
fprintf(stderr, "make_grid: malloc failed");
exit(1);
}
int j;
for(j = 0; j < y; j++) {
is[j] = (int*)malloc(sizeof(int) * x);
if(!is[j]) {
fprintf(stderr, "make_grid: malloc failed");
exit(1);
}
}
return is;
}
This isn't right at all but I can't put my finger on why. Can someone explain to me what to change like I'm five? (a five year-old who knows C, I guess)
I just copied your entire code and tried to run the program. The memory access violation (at least for me) is in this line:
int sidex = atoi(argv[0]);
int sidey = atoi(argv[1]); <-- memory access violation
The reason is (in my case at least) that I just ran the program with no arguments.
Now, even if I did provide the arguments on the command line the indexing is still off. The first argument argv[0] is the name of the executable, not the first argument after the name.
So, a few things to note for your code:
It is not guaranteed that there will be arguments. You should always check the argc to make sure you can index into argv
Those arguments are not guaranteed to be integer numbers either - you better check for that too, before you use them as your dimensions
Of course with the indexing shift you should adjust for your "array reading" code accordingly as well. But once you fix the indexing this should be an easy one for you
You are not declaring a two-dimensional array with that syntax, so the memory is not aligned the way you think, thus a segmentation fault. Declaring a pointer int** does not make it a 2-D array. (Surely you don't think int *** would get you a data cube ?).
Heap allocate a 2D array (not array of pointers)
One of the comments above gives the other problem, the zero parameter to a C program argv[0] is the name of the program, not the first parameter on the command line, that is argv[1].
Im currently working on a project (for school, yes) in which i've spent quite a few hours trying to get it to work, but now i found myself with an error that i cant seem to solve, and so i came here looking for help. The following is the code that i think is necessary, not the full code.
typedef struct
{
int day, month, year;
} typeDate;
typedef struct
{
int number;
char name[20];
char lastname[20];
typeDate date_of_birth;
} typeCard;
typedef struct
{
int associate_number;
typeCard associates[MAX_ELEM];
} typeAssociation;
typeDate date;
typeCard card;
typeCard aux;
int get_data(typeAssociation association)
{
association.associate_number = 0;
int e, i;
FILE* read = fopen("associados.txt", "r");
for (i = 0; fscanf(read, "%s %s %d %d %d %d", card.name, card.lastname, &card.number,
&date.day, &date.month, &date.year)
!= EOF;
i++)
{
association.associate_number++;
card.date_of_birth = date;
association.associates[i] = card;
}
fclose(read);
printf("Sort list[1/2/3]?");
scanf("%d", &e);
if (e == 1)
{
ordenar_n(&associacao);
}
(...)
}
int sort_by_date(typeAssociation association)
{
int g, m, i;
for (i = 0; i < association.associate_number - 1; i++)
{
m = i;
for (g = i + 1; g < data.year; g++)
{
if (date.year[g] < date.year[m])
{
m = g;
}
if (date.year[g] == date.year[m])
{
if (date.month[g] < date.month[m])
{
m = g;
}
else if (date.month[g] == date.month[m])
{
if (date.day[g] < date.day[m])
{
m = g;
}
}
}
aux = association.associates[i];
association.associates[i] = association.associates[m];
association.associates[m] = aux;
}
}
}
on another file i have (after calling the file):
int main(void)
{
typeAssociation association;
get_data(association);
}
The error is in the function sort_by_date and this function is supposed to sort a list (given by associados.txt) by date (stored in the struct typeDate) (from newest member to the oldest). I think (correct me if I'm wrong) i have the general idea going, but not the code. Can anyone help me? (it's my first post so sorry for any mistakes).
My error is in the function sort_by_date.
You are passing typeAssociation by value. Your sort is not applying to the object passed in. Also, don't write your own sort. qsort is a library function.
int sort_by_date(typeAssociation *association)
{
qsort(association->associates, association->associate_number, sizeof(typeCard), compare_typeCard);
}
int compare_typeCard(const void *avoid, const void *bvoid)
{
typeCard *a = avoid;
typeCard *b = bvoid;
/* put your comparison code here */
}
And, you have the same pass-by-value mistake calling getAssociation.
You need to pass address of typeAssociation variable.
Also in your code, you are comparing array elements with some global variables which is wrong.
int sort_by_date(typeAssociation *association)
{
int g=0, m=0, i=0;
for (i = 0; i < association->associate_number - 2; i++)
{
m = i;
for (g = i + 1; g < association->associate_number; g++)
{
if (association->associates[g].date.year < association->associates[m].date.year)
{
m = g;
}
else if (association->associates[g].date.year == association->associates[m].date.year)
{
if (association->associates[g].date.month < association->associates[m].date.month)
{
m = g;
}
else if (association->associates[g].date.month == association->associates[m].date.month)
{
if (association->associates[g].date.day < association->associates[m].date.day)
{
m = g;
}
}
}
}
//No need to do it in i loop
if(i != m)
{
aux = association.associates[i];
association.associates[i] = association.associates[m];
association.associates[m] = aux;
}
}
return 0; //Need to return an int value.
}
I need to create a program which would ask from user to input a string and then function in program needs to separate it to 2 strings of same size (user always inputs even number of chars) and after that it has to "shuffle" them...
So it should basically do this:
user inputs: A1B1C1D1
code should make 2 same sized strings: A1B1 and C1D1 and after that it should "shuffle" them to look like this: A1C1B1D1.
So it needs to take first 2 elements of first string, then first 2 elements of second string and so on…
My problem is that when I input A1B1C1D1, after I run the program, I get AC1BD1 (it leaves out 2nd char from first array).
#include<stdio.h>
#include<string.h>
#define N 100
void shuffle(char *cards) {
int i, n, x=0, c1=0, c2=0, j=0;
char tmp1[N]={0}, tmp2[N]={0};
n=strlen(cards);
//divide to 2 arrays with same number of elements
for(i=0; i<n; i++){
if(i<(n/2)){
tmp1[i]=cards[i];}
else{
tmp2[x]=cards[i];
x++;
}
}
//storing 2 elements from first array, then 2 elements from second array and so on
for(i=0; i<n; i++){
if(j>3){
j=0;
}
if(j<=1){ // store 2 elements from 1st array
cards[i]=tmp1[c1];
c1++;
j++;
}
if(j>=2){ // store 2 elements from 2nd array
cards[i]=tmp2[c2];
c2++;
j++;
}
}
printf("1st half:%s\n2nd half:%s", tmp1, tmp2);
printf("\n\t%s",cards);
return;
}
int main() {
char cards[N];
scanf("%s", cards);
shuffle(cards);
return 0;
}
The problem is here
if(j<=1){ // store 2 elements from 1st array
cards[i]=tmp1[c1];
c1++;
j++;
}
if(j>=2){ // store 2 elements from 2nd array
cards[i]=tmp2[c2];
c2++;
j++;
}
Make the second if as an "else if" (just an "else" is also enough)
What happens is that after you increment j from 1 to 2, you go into the second if statement, and rewrite on the same index on cards.
If you don't mind an alternative suggestion for "shuffling your deck of cards" in a much simpler way:
void shuffle(char *cards)
{
char tmp[N]={0};
int n = strlen(cards);
for (int i=0; i<n/2; i++)
tmp[i*2+0] = cards[i];
for (int i=0; i<n/2; i++)
tmp[i*2+1] = cards[i+n/2];
for (int i=0; i<n; i++)
cards[i] = tmp[i];
}
You call it shuffle and cards.
Wouldnt it be better to make a card structure that has two elements?
I thinky your j in the for loop is behaving wrong.
I will double check this and edit this answer if it wasnt j.
EDIT:
Your cradcount was off by a bit and you wrote the wrong index.
Here is some working code:
j = 0;
i = 0;
while(i<n)
{
++j;
if(j == 1 || j == 2)
{ // store 2 elements from 1st array
cards[i++]=tmp1[c1++];
}
else if(j == 3 || j == 4)
{ // store 2 elements from 2nd array
cards[i++]=tmp2[c2++];
}
else
{
j = 0;
}
}
In general you can use the debugger to see whats happening with your index. I assume this is homework and you have to write "optimal code". In general it would be beneficial to use varaiblaenames with more meaning.
EDIT2:
There is a nice solution below that illustrates time optimized code.
I wanted to add some code that i think is easier to read and maintain.
#include<stdio.h>
#include<string.h>
#define DECK_MAX 100
typedef struct
{
char group;
int number;
}Tcard;
typedef struct
{
Tcard card[DECK_MAX];
int count;
}Tdeck;
int ReadDeck(Tdeck * deck, const char *cardstring);
int DeckAddCopy(Tdeck * deck, Tcard * card);
int PrintDeck(Tdeck * deck, const char *deckname);
int InterleaveDecksCopy(Tdeck * target, Tdeck * source[], int sourcecount);
int SplitDeckCopy(Tdeck * source, Tdeck * target[], int targetcount);
int main() {
int e = 0;
char cardstring[100];
Tdeck deck, stackA, stackB, interleaved;
Tdeck * stacks[] = {&stackA, &stackB};
printf("Please input a cardstring: ");
scanf("%s", cardstring);
e |= ReadDeck(&deck, cardstring);
e |= PrintDeck(&deck, "cardstring");
e |= SplitDeckCopy(&deck, stacks, sizeof(stacks) / sizeof(Tdeck*) );
e |= PrintDeck(&stackA, "1st half");
e |= PrintDeck(&stackB, "2nd half");
e |= InterleaveDecksCopy(&interleaved, stacks, sizeof(stacks) / sizeof(Tdeck*) );
e |= PrintDeck(&interleaved, "interleaved");
if( e != 0) printf("There was an error dureing execution.\n");
return e;
}
int ReadDeck(Tdeck * deck, const char *cardstring)
{
int e = 0;
int varCount, n, total = 0;
Tcard card;
memset(deck, 0, sizeof(Tdeck));
do{
n = 0;
varCount = sscanf(&cardstring[total], "%c%i%n", &card.group, &card.number, &n);
total += n;
if( varCount == 2 )
{
//check if card is valid?
e |= DeckAddCopy(deck, &card);
}
else
{
if(strlen(cardstring) != total)
{
//string was not read completely
e |= 1;
}
}
}while(varCount == 2);
return e;
}
int DeckAddCopy(Tdeck * deck, Tcard * card)
{
int e = 0;
if(deck->count >= DECK_MAX)
{
e |= 1;
}
else
{
memcpy(&deck->card[deck->count++], card, sizeof(Tcard));
}
return e;
}
int PrintDeck(Tdeck * deck, const char *deckname)
{
int c;
printf("%s contains %i cards%s", deckname, deck->count, (deck->count == 0)? ".\n":": ");
for(c = 0; c < deck->count; ++c)
{
printf("%c%i%s", deck->card[c].group, deck->card[c].number, ( c+1 < deck->count) ? ", ":".\n");
}
return 0;
}
int InterleaveDecksCopy(Tdeck * target, Tdeck * source[], int sourcecount)
{
int c, s, e = 0;
memset(target, 0, sizeof(Tdeck));
for(c = 0; c < DECK_MAX; ++c)
{
for(s = 0; s < sourcecount ; ++s)
{
if(c < source[s]->count)
{
e |= DeckAddCopy(target, &source[s]->card[c]);
}
}
}
return e;
}
int SplitDeckCopy(Tdeck * source, Tdeck * target[], int targetcount)
{
int c, t, e = 0;
for(t = 0; t < targetcount ; ++t)
{
memset(target[t], 0, sizeof(Tdeck));
}
c = 0;
for(t = 0; t < targetcount ; ++t)
{
int cMax = (source->count) - (((source->count)/targetcount) * targetcount - t - 1 );
for( ; c < (t+1)*(source->count)/targetcount ; ++c)
{
e |= DeckAddCopy(target[t], &source->card[c]);
}
}
return e;
}