C - Write program to copy one string to another string and replace all all the vowels from the first string to @

Requirements

Write program to copy one string to another string and replace all all the vowels from the first string to @

Create two char buffers by using a pointer and malloc().

Demo

#include <stdio.h>
#include <stdlib.h>

int main()//from  w  w w .j a  v  a2  s .co  m
{
    char *input1,*input2;
    char *i1,*i2;

    input1 = (char *)malloc(sizeof(char)*1024);
    input2 = (char *)malloc(sizeof(char)*1024);
    if(input1==NULL || input2==NULL)
    {
        puts("Unable to allocate buffer! Oh no!");
        exit(1);
    }

    puts("Type something long and boring:");
    fgets(input1,1023,stdin);

    puts("Copying buffer...");
    i1=input1; i2=input2;
    while(*i1 != '\n')
    {
        switch(*i1)
        {
            case 'a':
            case 'A':
            case 'e':
            case 'E':
            case 'i':
            case 'I':
            case 'o':
            case 'O':
            case 'u':
            case 'U':
                *i2++='@';
                i1++;
                break;
            default:
                *i2++=*i1++;
        }
    }
    *i2 = '\0';

    printf("Original text:\n\"%s\"\n",input1);
    printf("Duplicate text:\n\"%s\"\n",input2);

    return(0);
}

Result

Related Exercise