Accessing characters of string

FCC's Avatar, Join Date: May 2008
Newbie Member
Hi all,

I am brand new to C and I am having so much trouble grasping the basics of it. Consider this code:

char *s = "this is my string";
printf("%s", s[3]);
When I do run this code, I get this error 'Segmentation Fault." I don't really get why...I am just trying to print out like a letter from my string. I read this has to do with trying to access a part of memory that I am not allowed to access? Can anyone explain how to get around this?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Just try this
char *s = "this is my string";
char c = s[3];
printf("%s,%c", s, c);