Leal9001

subs.c

Nov 14th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. #define bool int
  6. #define TRUE 1
  7. #define FALSE 0
  8.  
  9. #define MAX_WORD_LENGTH 81
  10. #define MAX_WORD 10
  11. #define MAX_TEXT_LENGTH 8000
  12.  
  13. int quantas_palavras () {
  14.     int num;
  15.     do {
  16.         scanf(" %d", &num);
  17.         if ((num < 1) || (num > MAX_WORD))
  18.             printf("O número de palavras deve ser > 0 e < %d!\n", MAX_WORD);
  19.      } while ((num < 1 || num > MAX_WORD));
  20.      return num;
  21. }
  22.  
  23. void ler_substituicoes (int num, char desaparecer[][MAX_WORD_LENGTH], char colocar[][MAX_WORD_LENGTH]) {
  24.     int i=0;
  25.     while (i<num) {
  26.         scanf("%s", desaparecer[i]);
  27.         i++;
  28.     }
  29.     for (i=0;i<num;i++) scanf("%s", colocar[i]);
  30. }
  31.  
  32. bool le_texto(char * text, int maximo) {
  33.     int i=0;
  34.    
  35.     do {
  36.         //scanf("%c", &text[i]);
  37.         text[i] = getchar();
  38.         i++;
  39.     } while (text[i] != '\0');
  40. }
  41.  
  42. void substitui_texto(int num, char retirar[][MAX_WORD_LENGTH], char colocar[][MAX_WORD_LENGTH], char * text, char * text_changed) {
  43.  
  44. }
  45.  
  46. main() {
  47.     int   n_word= 0; // Número de palavras no array word
  48.     char  desaparecer[MAX_WORD][MAX_WORD_LENGTH]; // a substituir
  49.     char  colocar[MAX_WORD][MAX_WORD_LENGTH]; // Substituições
  50.     char  text[MAX_TEXT_LENGTH];            // Texto inicial
  51.     char  text_changed[MAX_TEXT_LENGTH];    // Texto modificado
  52.     printf("Quantas palavras tem a lista de substituicao?\n");
  53.     n_word = quantas_palavras ();
  54.     printf("Introduza os textos a retirar e a colocar\n");
  55.     ler_substituicoes(n_word, desaparecer, colocar);
  56.     printf("Introduza o texto inicial. ");
  57.     printf("Termine com uma linha apenas com um ponto final:\n");
  58.     if (!le_texto(text, MAX_TEXT_LENGTH)) {
  59.          printf("Não foi introduzido texto\n");
  60.          return;
  61.     }
  62.   substitui_texto(n_word,desaparecer,colocar,text, text_changed);
  63.     printf("O texto inicial eh:\n%s\n", text);
  64.     printf("O texto substituido eh:\n%s\n", text_changed);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment