passing a string from one variable to another
hello, im trying to write a program that involves me needing to be able to arrange a bunch of names in a specific order that have been scanned from a file.
the exact order is determined by a function i wrote that compares a bunch of numerical values as show:
Code:
void sort(double ppg[999], int numPlayers) {
int y, x;
// These keep it within range of datafile
for (x = numPlayers - 1; x > 0; x = x - 1)
for (y = 0; y < x; y = y + 1)
if (ppg[y] < ppg[y+1]) // Compare size of integers
swap(&ppg[y], &ppg[y+1]);
}
void swap(double *a, double *b) {
double temp;
temp = *a;
*a = *b;
*b = temp;
}
this code just compares two numbers and swaps them based on which is greater. however, a lot of the data i have to swap is strings of first names, last names etc..
so i was wondering if anyone knows how i could transfer the string in one variable into a second variable (to basically get the same effect as switching numbers)
i tried this:
Code:
void charswap(char *c[20], char *d[20]) {
char temp[20];
temp = *c;
*c = *d;
*d = temp;
}
but i got an error and i dont think strings can simply be set to equal a different variable to swap them the same way as a number would.
so does anyone know how to pass a string from one variable to another?