The reason I use separate strings within the array "A","B","C" etc is so that when I input a number it can correspond to one of the letters via a number. If I make the array one string "ABCDEFG" then wont everything be considered 1? Or would I HAVE to make a multidimensional array?
you are outputting the char you just changed... the array is probably correct... i have a little work to do... i~ll be back in a bit if someone doesn~t answer first
pphrase5 should be a char not a char* and should = 'x' if you are going to do that...
right now you are setting the char pointers in your string array to point to where the x is... if this is an assignment, that will be really bad. you should be changing the value, not the pointer.
to change the value you actually have to do something like this
1 2 3 4 5 6
for(i = 1; i < 26; i = i +2)
{
pletter2[i][0] = pphrase5[0];
cout <<pletter2[i]; // you can still do this though, it's just a char array
}
because pphrase5 has to change type also... you are making an array of char so pphrase5 shouldn't be a char* and should be set to a char... if you already did that, then pprase5 needs to equal a char so "A" is a char array that equals {'A','\0'}, not a char
I tried making the array all one string but it does not work.... unless I have to take away the * from everything? If I took the asterisk away wouldn't that take away the pointer definition from everything? I wanted to use pointers.
Sorry for being so complicated. I understand if I use char and not char* I can access the array differently but I am trying to use pointers for this assignment even though they are more confusing for me haha. Thanks for your help and explanations.
I understand the test replaces the first letter of hello world with x so the output is xello world because it made str[0] = 'x'; but that is with a char type and Im using char*.
I am just confused as to how i can replace letters within the array with x and still have the output show AxCxExGxIxKxMxOxQxSxUxWxYx rather than simply only showing xxxxxxxxxxxxxx ? Sorry again if I am being annyoing.
FINALLY I don't know how I came up with this but I just did all by myself :D. With some help from you forum guys too >.<. Thanks. For some reason it printed 13 times which is half of 26 which is how many chars i have in my array. So I fiddled with the nested for loop but that changed how long the array printed horizontally not vertically. Then I fiddled with the first for loop and for some reason when I changed i<26 to i<2 it printed the correct output!.
1 2 3 4 5 6 7 8 9 10 11
for(i = 1; i < 2; i = i +2)
{
pletter2[i] = pphrase5;
for(int j = 0; j<26; j = j+2)
cout <<pletter2[j]<<pletter2[i];
cout <<endl;
}
I am not sure how to do this with 1 instance of the array but I did it with 2 for now. If you could help with using 1 instance of the array I would be much obliged.