I am trying to run the following code which takes string parameter and returns the length of the string in characters in C language using Visual Studio Code, but I am getting:
Error message:
ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Here is my code:
int str_length(char *mystring){
int i=0;
for(i=0; mystring[i]!='\0'; i++);
return i;
}
void alpha(){
printf("%d\n", str_length("-h=123"));
printf("%d\n", str_length(""));
}
I am stuck with this task, maybe you could provide a possible solution or some parts of the code that I have to change?