I am writing my own implementation of ToLower(char *str) in C. But i am getting segmentation fault in the function. The function which i wrote is :
void ToLower(
You are almost certainly failing when you call it like:
int main(void)
{
ToLower("HelloWorld");
return 0;
}
This is because "HelloWorld"
is a literal, constant string, and you cannot change its contents.
Try instead:
int main(void)
{
char str[] = "HelloWorld";
// Now str is your own local buffer, that you can modify.
// It is initialized with the text, but that text can be changed.
ToLower(str);
return 0;
}