Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,897 answers

573 users

How to change every letter in a string with the letter following it in the alphabet using C

1 Answer

0 votes
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

char* changeLettersWithFollowingLetter(char* str) {
    char* result = malloc(strlen(str) + 1);
    
    int i = 0;
    while (str[i] != '\0') {
        int asciiCode = (int)str[i] + 1;
        
        if ((asciiCode >= 97 && asciiCode <= 122) || (asciiCode >= 65 && asciiCode <= 90)) {
            result[i] = (char)asciiCode;
        } else {
            result[i] = str[i];
        }
        
        i++;
    }
    
    result[i] = '\0';
    
    return result;
}

int main() {
    char* result = changeLettersWithFollowingLetter("8a Frk");
    
    printf("%s\n", result);
    
    free(result);
    
    return 0;
}


 
 
/*
run:
    
8b Gsl
    
*/

 





answered Mar 1 by avibootz
...