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;
}
Salem commented: LEARN TO USE THE CODE TAGS -2
iamthwee commented: eualiser +12

Recommended Answers

All 5 Replies

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.

<accidentally deleted>

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).

Member Avatar for iamthwee

try using a string.

>> 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.