Advertisement
FoxTuGa

Codificação

Dec 13th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5.  
  6. #define TRUE 1
  7.  
  8. void Menu(char *option);
  9. void MENU_Codificar(char *input);
  10. void Read_Word(char *input);
  11.  
  12. int main() {
  13.     char input[255], option;
  14.     option = input[0] = '\0';
  15.  
  16.     while(TRUE) {
  17.         Menu(&option);
  18.         Read_Word(input);
  19.         if(option == 'q')
  20.             MENU_Codificar(input);
  21.        
  22.             //TODO: Menu de descodificar
  23.     }
  24.     return 0;
  25. }
  26.  
  27. void Menu(char *option) {
  28.  
  29.     printf("\t\t Menu Principal\n");
  30.     printf("\tq - Codificar\n");
  31.     printf("\tw - Descodificar\n");
  32.     while(*option != 'q' && *option != 'w') {
  33.         fflush(stdin);
  34.         *option = getch();
  35.     }
  36.     system("cls");
  37. }
  38.  
  39.  
  40. void MENU_Codificar(char *input) {
  41.     char word_out[255];
  42.     int idx, control, comp;
  43.  
  44.     comp = strlen(input);
  45.     control = 1;
  46.     for(idx=0; idx < comp;idx++, control++) {
  47.         if(control % 2 != 0)
  48.             word_out[idx] = *(input+idx);
  49.         else
  50.             word_out[comp-idx] = *(input+idx);
  51.     }
  52.  
  53.     word_out[idx+1] = '\0';
  54.     system("cls");
  55.     printf("Palavra original: %s\n", input);
  56.     printf("Palavra codificada: %s\n", word_out);
  57.     system("cls");
  58. }
  59.  
  60. void Read_Word(char *input) {
  61.  
  62.     printf("Palavra: ");
  63.     gets(input);
  64.     system("cls");
  65. }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement