int main()
{
char *S=new char[6];
S=“SAGAR”;
S[1]='s';
cout<<S;
}
Why I am getting error: segmnetation core dumped?
int main()
{
char *S=new char[6];
S=“SAGAR”;
S[1]='s';
cout<<S;
}
Why I am getting error: segmnetation core dumped?
Why not a single thing make sense here? Title and your code are nowhere close, how can someone help you if someone can’t read your code properly.
Simple Solution :
iterate through the string and check
if (s[i]>='A' && s[i] <='Z')
s[i] = s[i]-'A'+'a';
or you can just change it using ASCII value difference (32) [if it is in uppercase]
s[i]-=32;
In the above code I just want to replace Upper case ‘S’ in Cstring “SAGAR” with lower case ‘s’.That’s All.
I would suggest to use string
int main()
{
char *S=new char[6];
strcpy(S,“SAGAR”);
S[1]='s';
cout<<S;
}
This works fine. I think you can’t assign directly.
That’s what i was asking be clear what you want to ask.(also everyone can see what you have edited)