Pointer Address == array element?

What I want to happen in my code below is rather than int p = *search(Which I explain below is actually equal to ascii value of "F", so 70). I want p to be equal to the element number that "F" in Files is located in the numberOfTimes c-string. See below comments in green for a more in depth example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  char * search;
  //..... (declared numbeofTimes, newArea)

  search = strstr(newArea, numberOfTimes);
 //search now holds the address of the start
 // of the char that numberOfTimes occurs in newArea
 // so if I searched "Files" and numberOfTimes is "c:programFiles\win32"
 // it returns the address of the F in that c-string. 
         if(search != NULL){
	    char *temp2 = new char[(int)dataHolder[a].size()+1];
	    strcpy_s(temp2, (int)dataHolder[a].size()+1, dataHolder[a].data());
             
          //Below where I set p = *search it isn't working
          //All it is doing is setting p = to the value
          //lets say typed Files, p = 70 (AscII for capital F)
          //What I want it to do is return the element number
          // of the address that the pointer points to. 
	 for(int p = *search; temp2[p] != '\0'; p++){
	     cout << temp2[p];
	    }
	 cout << endl;
Last edited on
1
2
3
for (int p = (search - newArea); temp2[p] != '\0'; p++){
    cout << temp2[p];
}

Alternatively...
1
2
3
for (const char* p = search; *p != '\0'; p++){
    cout << *p;
}
Thank you!
Topic archived. No new replies allowed.