All pastes #568469 Raw Edit

Untitled

public c v1 · immutable
·published 2007-06-15 15:29 UTC
rendered paste body
// The first three lines make the functions within//  the declared libraries available to the program.#include <stdio.h>#include <stdlib.h>#include <string.h>void performFileIO(const char *infile){  FILE *FileIn, *FileOut;  char inBuffer[BUFSIZ];  char tempBuffer[4];  char outStringData[256];  char *filesize, *endptr;  char onebyte, c;  int currentFile = 1, position = 0; //, tempInteger = 0;  // properly open the files for reading and appending  FileIn = fopen(infile, "rb");  if (FileIn == NULL) {    printf("The file could not be opened, please check your file and location before trying again.\n");    exit(1);  }  printf("Enter the name and path for the output file: ");  gets(inBuffer);  FileOut = fopen(inBuffer, "a");  // marks the header of a file found within the input file  unsigned char pattern[] = {0xFF, 0x57, 0x50, 0x43};  while (!feof(FileIn)) {    position++;    fread(&onebyte, sizeof(onebyte), 1, FileIn);    //if (fgetc(FileIn) == pattern[0]) {    if (onebyte == pattern[0]) {      tempBuffer[0] = pattern[0];      fread(tempBuffer + 1, sizeof(pattern) - 1, 1, FileIn);      //fread(tempBuffer, sizeof(pattern), 1, FileIn);      if (memcmp(pattern, tempBuffer, sizeof(pattern)) == 0) {        printf("Match Found.\n");         fseek(FileIn, 7, SEEK_CUR);        fread(tempBuffer, sizeof(pattern), 1, FileIn);        sprintf(outStringData, "%-5i\tOffset: %-12i\tSize: %d\n", currentFile++, position - 1, tempBuffer);        fwrite(outStringData, sizeof(char), strlen(outStringData), FileOut);        continue;      }      fseek(FileIn, -3, SEEK_CUR);    }  }    // close the files and at the same time flush the buffers  fclose(FileIn);  fclose(FileOut);}// program entry pointint main(int argc, char *argv[]){  char buffer[BUFSIZ];  printf("Please enter the name and path of the binary file: ");  gets(buffer);  performFileIO(buffer);  printf("\n Done!\n Press enter to exit\n");  getchar();  return 0;}