Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int cuentaA(FILE *);
- int main()
- {
- FILE *fp;
- fp = fopen("entrada.txt","rt");
- if(fp == NULL)
- {
- printf("ARCHIVO NO SE PUDO ABRIR\n");
- return EXIT_SUCCESS;
- }
- printf("total de letras a = %d",cuentaA(fp));
- int ret = fclose(fp);
- if(ret == EOF)
- {
- printf("ERROR AL CERRAR EL ARCHIVO");
- return EXIT_FAILURE;
- }
- return 0;
- }
- int cuentaA(FILE *fp)
- {
- int contador = 0;
- char caracter;
- while ((caracter = fgetc(fp)) != EOF)
- {
- if(caracter == 'a')
- {
- contador++;
- }
- }
- return contador;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement