Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define MAX 1000
- #define MIN 128
- #define BLOC 512
- #define LINE 256
- #define SBLOC 128
- #define TRUE 1
- #define FALSE 0
- int main()
- {
- FILE *fp;
- char *buffer = malloc(sizeof(char)*(MAX*MAX));
- //char *buffer1 = malloc(sizeof(char)*MIN);
- //char buffer1[MAX];
- char*startLoc =malloc(sizeof(char)*(MAX));
- char*currLoc = malloc(sizeof(char)*(MAX));
- char c = 0;
- int line = 0;
- int blockCount = 0;
- int scrapsCount = 0;
- long bookmark = 0;
- if(buffer == NULL)
- {
- perror("Error allocating memory.");
- return(-1);
- }
- /*
- if(buffer1 == NULL)
- {
- perror("Error allocating memory.");
- return(-1);
- }*/
- for(int i = 0; i < MAX; i++)
- {
- buffer[i] = '\0';
- //buffer1[i] = '\0';
- }
- char* filename = malloc(sizeof(char)*20);
- char* word = malloc(sizeof(char)*20);
- if(filename == NULL)
- {
- perror("Error allocating memory");
- return(-1);
- }
- printf("Please enter the name of the file you wish to open.");
- scanf("%s", filename);
- printf("Please enter the word you wish to seek in this file.");
- scanf("%s", word);
- if((fp = fopen(filename, "rb")) == NULL)
- {
- perror("Error opening file.");
- return(-1);
- }
- //Write the content of the file to output.
- while(!feof(fp))
- {
- fread(buffer, sizeof(char*), BLOC, fp);
- printf("\n\nCluster %d\n", blockCount);
- printf("\\nn%s\n", buffer);
- for(startLoc = buffer; *startLoc != '\0'; *(startLoc++))
- {
- if(*startLoc == "\n")
- line++;
- if((currLoc = strstr(startLoc, word))!= NULL)
- {
- startLoc = currLoc;
- printf("\n\nThe word %s is found on line %d", word, line);
- }
- }
- }
- printf("\n\nThis is a redundant test mechanic");
- fclose(fp);
- free(filename);
- free(buffer);
- free(word);
- //free(buffer1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement