Computer Scientists are Pretty Pessimistic

Saturday 5 September 2015

WAP to replace every space in a string with a hyphen, tab with a hash and digit with a slash.

#include <stdio.h>
#include <string.h>
int main ()
{
    char a[100];
    int i;
    printf("Enter a string: ");
    gets(a);
    for(i=0;i<a[i];i++)
    {
        if(a[i]==' ')
            a[i]='-';
        else if(a[i]=='\t')
            a[i]='#';
        else if(a[i]>='0'&&a[i]<='9')
            a[i]='\\';
        printf("%c",a[i]);
    }
    return 0;
}

No comments:

Post a Comment