Something like this would be a start:
Code:
#include <stdio.h>
#include <string.h>
#define OUT 0
#define IN 1
int search(void);
int main() {
int n=0;
n=search();
if(n>0)
printf("\nTarget statute found\n");
else
printf("\nTarget statute not found\n");
return 0;
}
int search(void) {
int state=OUT,len=0;
char end[]="HS. CODE ANN";
char *found=NULL;
char buff[120];
char target[20];
FILE *fp=fopen("Texas Statutes.txt","r");
if(!fp) {
perror("Error");
return -1;
}
//printf("Enter the statute: "); //these three lines of code
//fflush(stdout);
//fgets(target, 20, stdin); //are only REM'd out while debugging
strcpy(target, "481.115"); //remove when ready for testing other statutes
len = strlen(target)-1;
if(target[len]=='\n')
target[len]='\0';
while((fgets(buff, 120, fp)) != NULL) {
found=strstr(buff, target);
if(found) {
state=IN;
break;
}
}
printf("\n");
while(state==IN) {
printf("%s\n",buff);
fgets(buff, 120, fp);
if(strstr(buff, end))
state=OUT;
}
fclose(fp);
if(found)
return 1;
else
return 0;
}
You would want a more thorough test of the string that the user enters (the statute), etc.