ramontricolor12

LISTA 08 - Exercício 08

Aug 9th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. /*CABEÇALHO
  2.     Arquivo: LISTA 08 - Exercício 08.c
  3.     Objetivo: Inverter ua string.
  4.     Autor(a): Ramon Borges.
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. //PROTÓTIPO DE FUNÇÕES
  10. void inverteString(char *s);
  11.  
  12. int main()
  13. {
  14.     char nome[50];
  15.     printf("Informe um nome: ");
  16.     gets(nome);
  17.     inverteString(nome);
  18.     printf("\n%s", nome);
  19.     return 0;
  20. }
  21.  
  22. void inverteString(char *s)
  23. {
  24.     char aux;
  25.     int i = 0, maximo = 0, metade;
  26.     //calcula quantas letras possui a palavra.
  27.     while(s[i] != '\0')
  28.     {
  29.         maximo++;
  30.         i++;
  31.     }
  32.     //Processamento
  33.     metade = maximo/2;
  34.     for(i = 0; i < metade; i++)
  35.     {
  36.         aux = s[i];
  37.         s[i] = s[maximo - 1 - i];
  38.         s[maximo - 1 - i] = aux;
  39.     }
  40.     return;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment