I am new to this. I am trying to write code to update every other element in an array. Here is all I have.... can't find anything to show me how to do this.

#include<iostream>

using std::cout;
using std::endl;

int palpha = 0;


int main()
{
	char*  alphabet[] ={    "A",
							"B",
							"C",
							"D",
							"E",
							"F",
							"G",
							"H",
							"I",
							"J",
							"K",
							"L",
							"M",
							"N",
							"O",
							"P",
							"Q",
							"R",
							"S",
							"T",
							"U",
							"V",
							"W",
							"X",
							"Y",
							"Z",
						};
	//char* alphanew[26];
		

	While (palpha <= 26)
		//alpahnew = alphabet;
		palpha +=2;

	

	return 0;
}

I would appreciate any help you can give me.

Lynne

Edited 6 Years Ago by Nick Evan: Added CODE-tags

What exactly do you mean by updating? As in appending some information, incrementing the value of the char or how many times it is accessed? What exactly do you mean?

And please use code-tags for your code-

[CODE=c++] //...code  [/CODE] 

Edited 3 Years Ago by Dani: Formatting fixed

I need to add "x" to every other letter in the array so that I can print out Ax Cx Ex etc. I do not know how to append the "x" it he letter in the array and write it to another array.

I need to add "x" to every other letter in the array so that I can print out Ax Cx Ex etc. I do not know how to append the "x" it he letter in the array and write it to another array.

If you need to append letters, then don't initialize like this:

char* alphabet[] = {...};

You need something that can handle an increase in size. What's the longest a sting can be? Let's say 10.

char alphabet[26][11];  //add 1 to 10 for the NULL terminator.
//You can initialize using 26 strcpy statements or do a loop of some kind.
strcpy(alphabet[0], "A");
strcpy(alphabet[1], "B");
strcpy(alphabet[2], "C");

Now use strcat for concatenation

strcat(alphabet[0], "x");  // end up with "Ax"

Edited 6 Years Ago by VernonDozier: n/a

This article has been dead for over six months. Start a new discussion instead.