Is there a way to set a variable to equal an array
(ie. temp = name[index]) and then be able to set another array equal to that variable(ie. name[index + 1] = temp).
Yup. Exactly the way you just wrote it. Except when you say "array" and "another array," you really mean "element of an array" and "another element of an array (in this case, of the same array)."
I tried using the [index + 1] = temp) statement, but I get some: '=' : cannot convert from 'char *' to 'char [25]' compile time error. Here is (part of the) function (trying to sort words in a file): Any suggestions why I get this error.
void sort(char word[][25], int size, int& number)
{
using namespace std;
int index, result;
ifstream fin;
fin.open("bob.txt"
for(index = 0;! fin.eof() && index < 100; index++) //Fills Array
{
fin.getline(word[index], 25);
}
number = index;
for (index = 0; index < number; index ++)
{
result = strcmp(word[index], word[index +1]);
you have to do the full string copy to swap your two strings.
char temp[25];
strcpy(temp,word[index]);
strcpy (word[index], word[index +1]);
strcpy(word[index + 1], temp);
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.