ramontricolor12

LISTA 08 - Exercício 07

Aug 9th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. /*CABEÇALHO
  2.     Arquivo: LISTA 08 - Exercício 07.c
  3.     Objetivo: Escrever uma função similar a strlen da biblioteca do C.
  4.     Autor(a): Ramon Borges.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. int main()
  10. {
  11.     char *nome;
  12.     nome = (char*) malloc(50 * sizeof(char));
  13.     int qtde;
  14.     printf("Informe um nome: ");
  15.     gets(nome);
  16.     qtde = funcaoStrlen(nome);
  17.     printf("\nA palavra %s possui %d letras.", nome, qtde);
  18.     free(nome);
  19.     return 0;
  20. }
  21.  
  22. int funcaoStrlen(char *palavra)
  23. {
  24.     int cont = 0;
  25.     while(*palavra != '\0')
  26.     {
  27.         cont++;
  28.         palavra++;
  29.     }
  30.     return cont;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment