View Single Post
Old 09-12-2005, 11:11 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Something like this in C
Code:
#include <stdio.h>
#include <string.h>
#define BUFF_LENGTH 256

int main(int argc, char* argv[])
{
  FILE* in_file, out_file;
  char buffer[BUFF_LENGTH +1];
  int skip = 0;
  if(argc != 4)
    {
      printf("Usage: %s <in_file> <out_file> <delim_word>\n", argv[0]);
      return -1;
    }
  if(!(in_file = fopen(argv[1], "r")))
    {
      printf("Error opening input file %s\n", argv[1]);
      return -1;
    }
  if(!(out_file = fopen(argv[2], "w")))
    {
      printf("Error opening output file %s\n", argv[2]);
      fclose(in_file);
      return -1;
    }
  while(!feof(in_file))
    {
      if(!fgets(buffer, BUFF_LENGTH, in_file))
	{
	  printf("Error reading from file %s\n", argv[1]);
	  fclose(in_file);
	  fclose(out_file);
	  return -1;
	}
      if(!skip)
	if(strstr(buffer, argv[3]))
	  skip = 1;
      if(skip)
	if(!fwrite(buffer, strlen(buffer), 1, out_file))
	  {
	    printf("Error writing to file %s\n", argv[2]);
	    fclose(in_file);
	    fclose(out_file);
	    return -1;
	  }
    }
  if(!skip)
    printf("The word \"%s\" wasn't found in file %s\n", argv[3], argv[1]);
  fclose(in_file);
  fclose(out_file);
  return 0;
}
Note: None of the above code has been tested, not even compiled, but it should work
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote