Repeats an input line but replaces each non-space character with the character that follows it in the ASCII code sequence. - C String

C examples for String:char array

Description

Repeats an input line but replaces each non-space character with the character that follows it in the ASCII code sequence.

Demo Code

#include <stdio.h>
#define SPACE ' '             // that's quote-space-quote 

int main(void){
    char ch;//  ww w.  ja va2s  . c  om
    
    ch = getchar();           // read a character         
    while (ch != '\n')        // while not end of line    
    {
        if (ch == SPACE)      // leave the space          
            putchar(ch);      // character unchanged      
        else
            putchar(ch + 1);  // change other characters  
        ch = getchar();       // get next character       
    }
    putchar(ch);              // print the newline
    
    return 0;
}

Result


Related Tutorials