Hello,
I am trying to write a function to extract a number of characters in a file name given to a function up to the '.' character.
My function is below. I am trying to copy the characters pointed to by the fName pointer to a data member dataSetName up to the '.' operator reached in the fName pointer.
For some reason I get no output for the dataSetName. Why is this not working?Code:void Layer::setDataSetName(char * fName) { int result; //result buffer //if it is a featureclass if(result = (strcmp(layerType, "featureclass") == 0)) { int count = 0; //holds count of characters in argument //count num of characters up to the '.' character for(int i = 0; fName[i] != '.'; i++) { ++count; } cout << "count is " << count << endl; //allocate space for the dataSetName dataSetName = new char[count + 1]; //copy the characters up the '.' character for(; *fName != '.'; fName++, dataSetName++) { *dataSetName = *fName; cout << "*dataSetName = " << *dataSetName << " *fName = " << *fName << endl; } //place a null character after the last character *dataSetName = '\0'; } //end if a featureclass //else it is an image else { //keep the extension dataSetName = new char[strlen(fName) + 1]; strcpy(dataSetName, fName); } //end else it is an image } //end setDataSetName



LinkBack URL
About LinkBacks


