#include #include // basic implementation void underscorify(char* s) { char* p = s; while (*p != 0) { if (*p == ' ') { *p = '_'; } p++; } } // how a developer might code it void underscorify2(char* s) { char* p; for (p = s; *p ; p++) { if (*p == ' ') { *p = '_'; } } } // how a kernel hacker might code it void underscorify3(char* s) { for ( ; *s ; s++) { if (*s == ' ') *s = '_'; } } void underscorify_bad(char* s) { char* p = s; while (*p != '0') { if (*p == 0) { *p = '_'; } p++; } } void underscorify_bad2(char* s) { char* p = s; while (*p != '0') { if (*p == ' ') { *p = '_'; } p++; } } int main() { char msg[] = "Here are words"; puts(msg); underscorify_bad2(msg); puts(msg); }