I am just learning some pointers stuff in C and I happened to learn that using the * one can dereference the pointer. So I wrote the following code to check for that.
#include<stdio.h>
#include<string.h>
char *findChar(char *s, char c){
while(*s!=c){
s++;
}
return s;
}
int main(){
char myChar='a';
const char myString[]="Hello abhishek";
char *location;
location = findChar(myString,myChar);
puts(location);
char temp = *location;
printf(temp);
}
I assume that temp should get the value pointed by the character pointer location, But this program is giving me a segmentation fault. Please clearify what I am doing wrong?