Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- main()
- {
- FILE ptr_arq;
- char palavra[26], arq[50], *arqui, ch[301];
- int linha = 0;
- int i = 0;
- printf("Por favor, digite qual eh a palavra que voce deseja procurar | NO MAX 25 CARACTERES | : ");
- fflush(stdin);
- gets(palavra);
- printf("por favor, digite qual eh o nome do seu arquivo e tambem o tipo desse arquivo que voce deseja ler: ");
- fflush(stdin);
- gets(arq);
- ptr_arq = fopen(arq, "r");
- if (ptr_arq = fopen(arq, "r")) == NULL)
- {
- printf("Desculpe, nao conseguimos abrir o arquivo");
- }
- while(fgets(ch,300,ptr_arq) != NULL )
- {
- arqui=strstr(ch,palavra);
- if (arq != 0)
- {
- printf("Essa palavra esta contida no texto");
- printf("A linha que esta palavra esta eh a: ", %d);
- printf("e o conteudo da linha eh o seguinte: \n %s", linha+1,ch);
- }
- linha++
- }
- if(i==0)
- {
- printf("A palavra nao esta no arquivo. Desculpe.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement