Advertisement
Guest User

exercicio

a guest
Dec 1st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7.  
  8. main()
  9. {
  10. FILE ptr_arq;
  11. char palavra[26], arq[50], *arqui, ch[301];
  12.  
  13. int linha = 0;
  14.  
  15. int i = 0;
  16.  
  17. printf("Por favor, digite qual eh a palavra que voce deseja procurar | NO MAX 25 CARACTERES | : ");
  18. fflush(stdin);
  19. gets(palavra);
  20.  
  21.  
  22. printf("por favor, digite qual eh o nome do seu arquivo e tambem o tipo desse arquivo que voce deseja ler: ");
  23. fflush(stdin);
  24. gets(arq);
  25.  
  26. ptr_arq = fopen(arq, "r");
  27.  
  28. if (ptr_arq = fopen(arq, "r")) == NULL)
  29. {
  30. printf("Desculpe, nao conseguimos abrir o arquivo");
  31.  
  32.  
  33. }
  34.  
  35.  
  36. while(fgets(ch,300,ptr_arq) != NULL )
  37. {
  38.  
  39. arqui=strstr(ch,palavra);
  40. if (arq != 0)
  41. {
  42.  
  43. printf("Essa palavra esta contida no texto");
  44.  
  45. printf("A linha que esta palavra esta eh a: ", %d);
  46.  
  47. printf("e o conteudo da linha eh o seguinte: \n %s", linha+1,ch);
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. }
  55.  
  56.  
  57.  
  58. linha++
  59.  
  60.  
  61. }
  62.  
  63.  
  64. if(i==0)
  65. {
  66. printf("A palavra nao esta no arquivo. Desculpe.");
  67. }
  68.  
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement