Hi
I try to compile that program to see the results but I encountered a problem. The error that is guven by my comiler is :
K undeclared (first use this function)
e undeclared
n undeclared
and so on

how my I make it compile thanks

#include <iostream>
int main()
{
using namespace std;
const int arraySize = 20;
char name1[ arraySize ] = { ’K’, ’e’, ’n’, ’n’, ’e’, ’t’, ’h’, ’\0’};
char name2[7] = { ’C’, ’l’, ’i’, ’f’, ’t’, ’o’, ’n’};
char name3[] = "Suzanne";
char name4[10] = "Elizabeth";
cout << "Array name1 contains: " << name1 << endl << endl;
cout << "Array name2 contains: " << name2 << endl << endl;
cout << "Array name3 contains: " << name3 << endl << endl;
cout << "Array name4 contains: " << name4 << endl << endl;
return 0;
}
Comments
eualiser
LEARN TO USE THE CODE TAGS

initialize the arrays like this:

char name1[ arraySize ] = "Kenneth";
char name2[7] = "Clifton";
char name3[] = "Suzanne";
char name4[10] = "Elizabeth";

Note that you might get buffer overflow errors -- I'll leave that up to you to fix.

it would appear that you're using the wrong kind of single-quote mark (Some character sets have several different ones). you should be using ' ' rather than ` `
(did you copy the code out of a word document or powerpoint presentation?)

Ancient Dragon's solution is the easiest (You'll have to resize the array to fit the extra '\0' character).

>> try to compile that program to see the results
your compiler told you the results didn't it? The result was that the compiler could not compile it due to syntax errors.

>> I cant because "Clifton" is to long for that array

No big deal -- just increase the array size. Even if you got it to work as in your original code (one character at a time) it don't work right because the string dones not contain the null terminating byte.

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