C examples for Function:Function Parameter
The following program adds a dash for each space in its string argument.
The const in the parameter declaration ensures that the code inside the function cannot modify the parameter.
#include <stdio.h> void sp_to_dash(const char *str); int main(void) { sp_to_dash("this is a test"); return 0;/*from w w w . j av a2 s .c o m*/ } void sp_to_dash(const char *str) { while (*str) { if (*str == ' ') printf("%c", '-'); else printf("%c", *str); str++; } }