Is it possible to reference (or point to) part of an array? Example:
Code:char name[]={'b','j','a','r','n','e','\0',}; char &jar=// 'j','a','r'
Is it possible to reference (or point to) part of an array? Example:
Code:char name[]={'b','j','a','r','n','e','\0',}; char &jar=// 'j','a','r'
char* jar = &name[1];
now a cout << jar << endl; would print "jarne"
Is there a way to terminate it at 'r' (i.e. "jar")?Originally Posted by Perspective
if you dont mind ruining the original string you can set the next char to '\0' (ie: name[4] = '\0';) otherwise you'll have to copy the part you want into a different memory location.
No, I didn't want to touch the original string. Thanks for your help.Originally Posted by Perspective
You could write a "substring" class that does that.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Do you know ahead of time how much of the string you will need or is that a runtime decision?