Read user input, alters input, preserving non-letters - C String

C examples for String:char array

Description

Read user input, alters input, preserving non-letters

Demo Code

#include <stdio.h>
#include <ctype.h>            // for isalpha()

int main(void){
    char ch;/*w  w  w.  j  av  a 2s.  c  o m*/
    
    while ((ch = getchar()) != '\n'){
    
        if (isalpha(ch))      // if a letter,
            putchar(ch + 1);  // display next letter
        else                  // otherwise,
            putchar(ch);      // display as is
    }
    putchar(ch);              // display the newline
    
    return 0;
}

Related Tutorials