I'm new to C++, and tried to start making a script that will shuffle an
array. Can someone please tell me what's wrong?
#include <iostream.h>
#include <string.h>
int main () {
srand(time(0));
int array_length;
int count;
int randm;
char temp[30];
cout << "How many items in array? ";
cin >> array_length;
char items [30][array_length + 1];
for (count = 0; count <= array_length; count++) {
if (count != 0) {
cout << "\nWhat shall item " << count << " be?\n\t";
}
cin.getline (items[count], 30);
}
for (count = 0; count < array_length; count++) {
randm = rand() % array_length;
strcpy (temp[30], items[30][count]);
//ERROR
strcpy (items[30][count], items[30][randm]); //ERROR
strcpy (items[30][randm], temp[30]); //ERROR
}
return 0;
}
Can someone please tell me what is wrong? The errors I get are:
21: error: invalid conversion from 'char' to 'char*'
21: error: invalid conversion from 'char' to 'const char*'
22: error: invalid conversion from 'char' to 'char*'
22: error: invalid conversion from 'char' to 'const char*'
23: error: invalid conversion from 'char' to 'char*'
23: error: invalid conversion from 'char' to 'const char*'
array. Can someone please tell me what's wrong?
#include <iostream.h>
#include <string.h>
int main () {
srand(time(0));
int array_length;
int count;
int randm;
char temp[30];
cout << "How many items in array? ";
cin >> array_length;
char items [30][array_length + 1];
for (count = 0; count <= array_length; count++) {
if (count != 0) {
cout << "\nWhat shall item " << count << " be?\n\t";
}
cin.getline (items[count], 30);
}
for (count = 0; count < array_length; count++) {
randm = rand() % array_length;
strcpy (temp[30], items[30][count]);
//ERROR
strcpy (items[30][count], items[30][randm]); //ERROR
strcpy (items[30][randm], temp[30]); //ERROR
}
return 0;
}
Can someone please tell me what is wrong? The errors I get are:
21: error: invalid conversion from 'char' to 'char*'
21: error: invalid conversion from 'char' to 'const char*'
22: error: invalid conversion from 'char' to 'char*'
22: error: invalid conversion from 'char' to 'const char*'
23: error: invalid conversion from 'char' to 'char*'
23: error: invalid conversion from 'char' to 'const char*'
Comment