Accessing characters of string

FCC
Newbie Member
22May2008,23:36   #1
FCC's Avatar
Hi all,

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

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?
Go4Expert Founder
23May2008,08:33   #2
shabbir's Avatar
Just try this
Code:
char *s = "this is my string";
char c = s[3];
printf("%s,%c", s, c);