Guest_imported
New member
- Jan 1, 1970
- 0
If I have an array of pointers to an array of strings and I want to redereference pointers,so that the pointer with lowest index will point to smallest string.I know two ways of doing this and one way gives me strange results and for the life of me I don't know why.
for(int j=0;j<10-1;j++)
{
int i=a;
for(;i<10;i++)
{
if(*pwords[j]>word)
{
pwords[j]=&word;
pwords=&word[j];
}
}
}
Why isn't this also the right way?I know there is an alternative to this by assigning adresses of pointers to pointers,but I want to know what is wrong with this code.I might write a very short text and it will output words in ascending order(which is supposed to do),but other times it will ignore some words when outputting it or it will repeat one word more then once).I sure hope someone can help me!
Thank you
for(int j=0;j<10-1;j++)
{
int i=a;
for(;i<10;i++)
{
if(*pwords[j]>word)
{
pwords[j]=&word;
pwords=&word[j];
}
}
}
Why isn't this also the right way?I know there is an alternative to this by assigning adresses of pointers to pointers,but I want to know what is wrong with this code.I might write a very short text and it will output words in ascending order(which is supposed to do),but other times it will ignore some words when outputting it or it will repeat one word more then once).I sure hope someone can help me!
Thank you