Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Small question about array

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
howdy all,
I got a question.Suppose I a code like this:

const int x=5;

void main()
{
char A[x],B[x];
int C;
cout<<&quot;Enter something; &quot;;
cin>>A;
C=strlen(A);

==Here is the question,
Sample run:
Enter something: Joe
and then strlen returns 3.
Now can I use the return value from strlen int C, and
use it as an array index like this?--> B[C]
I actually tried this and got an error, obviously I cant change a const but is there a right way to do what I would like it to do.
 
What const? There's nothing wrong with something like this, try it! Although I'm not sure quite what the point is...

char A[x],B[x] = &quot;help&quot;;
int c;
cout<<&quot;Enter something; &quot;;
cin>>A;
c=strlen(A);
B[c] = 'a';
cout << A << endl;
cout << B << endl; :) Hope that this helped! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top