Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: C  |  size: 0.82 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include<stdio.h>
  2.  
  3. int main (void) {
  4.        
  5.         int ctr = 0;
  6.        
  7.         printf("Cases:");
  8.         scanf("%d", &ctr);
  9.         getchar();
  10.        
  11.         while (ctr != 0) {
  12.                 int s = 0;
  13.                 int i = 0;
  14.                 char inp[50];
  15.                 char inp2[50];
  16.                
  17.                 printf("\nString:");
  18.                 scanf("%[^\n]s", inp);
  19.                 getchar();
  20.                        
  21.                 /*shift number*/
  22.                 printf("\nShift:");
  23.                 scanf("%d", &s);
  24.                 getchar();
  25.                
  26.                 /*changing the characters*/
  27.                 for(i = 0; inp[i] != '\0'; i++) {                      
  28.                         inp[i] = (int)inp[i] + s;
  29.                        
  30.                         if(inp[i] <= 'z'&& inp[i] >= 'a') {
  31.                                 if((int)inp[i] + s > 'z') {
  32.                                         inp2[i] = (int)inp[i] + 'a' - 1;
  33.                                 }
  34.                                 else if((int)inp[i] + s <= 'z') {
  35.                                         inp2[i] = (int)inp[i] + s;
  36.                                 }
  37.                         }
  38.                        
  39.                         /*retains the character space into space*/
  40.                         else if(32 == (int)inp[i]){
  41.                                 inp2[i] = 32;
  42.                         }
  43.                 }
  44.                
  45.                 printf("\n%s\n", inp);
  46.         ctr--;
  47.         }
  48.        
  49. return 0;
  50. }