Wednesday, January 19, 2011

String pattern






/****************************
* Umang B Bhatt *
* bhatt.umang7@gmail.com *
*****************************/

/**
* program for string pattern
*/

/**
* Enter string: Please validate my Input
* Output: Jnpvt my vbljdbtf Plfbsf
*/

/**
* here all the words of a string are printed in reverse order (the last word comes first, second last wor comes second and so on)
* here the order of words in the word is not changed.
* whenever we encounter A, E , I , O or U replace it with the next character (eg A with B, E with F
* and so on)
* extra spaces in the program are also ignored
*/




#include<stdio.h>

#include<string.h>

void
main()
{

char
arr[100][100] = {0};

/* this trick also works with the structure
* we can initialize whole structure using this technique
*/

int
x = 0, y = 0;

char
str[100];
int
i = 0;

printf("\nEnter string: ");
gets(str);
/*asusual warnings with gets*/

i = 0;

while
(str[i] != '\0' && i < strlen(str))
{


if
(str[i] == ' ' || str[i] == '\0')
{


while
(str[i] == ' ' && str[i] != '\0')
{


i++;
}
}

else

{

if
(str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U' || str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
{


arr[x][y] = str[i] +1 ;
y++;

i++;
}

else

{

arr[x][y] = str[i];

y++;
i++;
}

if
(str[i] == ' ' || str[i] == '\0')
{


arr[x][y] = '\0';
x++;
y = 0;
}

}
}


printf("Output:");
for
(i = x; i >= 0; i--)
{


printf(" %s", arr[i]);
}

printf("\n");

}


No comments:

Post a Comment