i have to write a program, in which i have to make pointer to point to the character, where it last occured in a string. For example:
String: Lord of the rings
Character: r
Pointer points to the last 'r' in the string, that is in the word 'rings'.
If there is no such character, than the pointer must return NULL.
I must use void StringSearch(IN String[], IN Ch, OUT Ptr);
i've written the program, but it's not working:
#include <stdio.h>
void StringSearch(char String[], char Ch, char *Ptr);
int main(){
char String[100], Ch, *Ptr;
fgets(String, sizeof String, stdin);
scanf("%c", &Ch);
StringSearch(String, Ch, *Ptr);
printf("%c", *Ptr);
getchar();
return 0;
}
void StringSearch(char String[], char Ch, char *Ptr){
int i = 0, j;
while(String[i]!= '\0'){
i++;
}
for (j = i; j >= 0; j--){
if(String[j] == Ch){
Ptr = &Ch;
return;
}
}
*Ptr = NULL;
}
i get an error: Run-Time Check Failure #3 - The variable 'Ptr' is being used without being defined on the line StringSearch(String, Ch, *Ptr);
and i don't know how to define it, because NULL must also come from the function and not from main().