Advertisement
sombriks

contar os a's

Jun 25th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. /*
  2.  * main.c
  3.  *
  4.  *  Created on: 03/06/2013
  5.  *      Author: sombriks
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. /*
  13.  *  receber uma string e contar qntos a tem nessa string
  14.  */
  15. int main(int argc, char **argv) {
  16.     // se escrever muito dá erro
  17.     char *buffer = malloc(1024 * sizeof(char));
  18.     memset(buffer, '\0', 1024);
  19.     printf("digite uma linha de texto (max. 1024 caracteres):\n");
  20.     gets(buffer);
  21.     int qtda = 0;
  22.     int i = 1024;
  23.     while (i--)
  24.         if (buffer[i] == 'a')
  25.             qtda++;
  26.     printf("a linha digitada contém %i letras a\n", qtda);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement