Advertisement
Guest User

Untitled

a guest
May 6th, 2017
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. * teste.c
  3. *
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. void funcion_2(const char *);
  11. int function_1(const char *);
  12.  
  13. void funcion_2(const char *arquivo){
  14.  
  15. function_1(arquivo);
  16. }
  17.  
  18. int function_1(const char *arquivo){
  19. FILE *fp;
  20. char* linha;
  21.  
  22. fp = fopen (arquivo, "r");
  23.  
  24. if (fp == NULL) {
  25. printf ("Houve um erro ao abrir o arquivo.\n");
  26. return 1;
  27. }
  28.  
  29. while( fgets(linha, 1024, fp) ){
  30. printf( "Nome: %s\n", strtok(linha, ";"));
  31. printf( "Mail: %s\n", strtok(NULL , ";"));
  32.  
  33. }
  34.  
  35. fclose(fp);
  36. return 0;
  37.  
  38. }
  39.  
  40. int main()
  41. {
  42. funcion_2("/tmp/mail.txt");
  43. function_1("/tmp/mail.txt");
  44. exit(0);
  45. }
  46.  
  47. /*** FIM teste.c ***/
  48.  
  49.  
  50.  
  51. /* mail.txt */
  52.  
  53. Maria da Silva;maria@email.com.br
  54. Joao Abrantes;joao@email.com.br
  55. Nelson Jobin;nelson@email.com.br
  56. Jose Sarney;jose@email.com.br
  57. Adriano de Souza;adriano@email.com.br
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement