Hello,
I am attempting to use pointer arithmetic to extract a certain portion of a string but have met nothing but errors.
I want to extract the characters from the original string (origStr) from the third character to the '.' character or the '_' character (whatever comes first).
I would like to output it to the monitor.
My code is below. Could someone tell me what is wrong?
Here are my compliation errors:Code:#include <iostream.h> //begin main int main() { char origStr[] = "alHello_0.shp"; char newStr[25]; //strip the name down to the component *newStr = *(origStr + 2); //set the pointer in a to the third character of b //eliminate the rest of the characters from either the _ or the . char for( ; (*origStr != '_') && (*origStr != '.'); origStr++, newStr++) { *newStr = *origStr; } ++newStr; //place a null at the present character *newStr = '\0'; cout << newStr << endl; return 0; } //end main
c:\temp\c++\pec\pec\test.cpp(13): error C2105: '++' needs l-value
c:\temp\c++\pec\pec\test.cpp(13): error C2105: '++' needs l-value
c:\temp\c++\pec\pec\test.cpp(16): error C2105: '++' needs l-value



LinkBack URL
About LinkBacks


