c++ - what is the error in that code? -
what error in code ??!!
hint : sp_to_dash()
function in following program prints dash each space in string argument. is, string "this test"
printed "this-is-a-test"
.
#include <stdio.h> void sp_to_dash( char *str); int main(void) { sp_to_dash("this test"); return 0; } void sp_to_dash( char *str) { while(*str) { if(*str==' ' ) *str = '-'; printf("%c", *str); str++; } }
string literals not modifiable. change way:
int main(void) { char str[] = "this test"; sp_to_dash(str); return 0; }
Comments
Post a Comment