delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/22/02:11:09

Message-Id: <199801220709.UAA24275@fep1-orange.clear.net.nz>
From: "Jamie Love" <jamie DOT love AT clear DOT net DOT nz>
To: "DJGPP mailing list" <djgpp AT delorie DOT com>
Subject: whats wromg with my file program? - HELP!
Date: Fri, 23 Jan 1998 08:11:57 +1300
MIME-Version: 1.0

Not specifically a djgpp question, but it does happen to involve the
djgpp.env file

So, can anyone tell my why, when I compile and run the binary with the
following command line:
(the sprites.set is certainly a real file)
remdefs sprites.set
I get the djgpp.env file!!! instead of the correct sprites.set file. BTW I
run this under dos.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>

int main(int argc, char *argv[])
 {
   char *data;
   int length;
   FILE *inFile;

   printf("Silicon Wanderers remove defines program from .set files.\n"
          "Programmed 22 Jan 1998 by Jamie Love.\n"
          "Opening %s\n", argv[1]);

   /*in case the user does not know how to do it*/
   if(argc != 2)
    {
      printf("Usage 'remdefs file.set'");
      return 0;
    }

   inFile = fopen(argv[1], "r");

   if(inFile == NULL)
    {
      printf("Error: unable to open %s", argv[1]);
      return 0;
    }

   fseek(inFile, 0, SEEK_END);
   length = ftell(inFile);

   data = malloc(length);

   *(data + length) = 0;

   if(data == NULL)
    {
      printf("Error: unable to malloc %d bytes of memory for buffer",
length);
      return 0;
    }

   fseek(inFile, 0, SEEK_SET);

   if((length = fread(data, 1, length, inFile)) != -1)
    {
      printf("Error: unable to read %d bytes from %s", length, argv[1]);
      return 0;
    }

   printf("%s\n", data);
   getch();

   fclose(inFile);
   return 1;
}

Jamie Love
Part of the Silicon Wanderers
(http://www.geocities.com/SiliconValley/Horizon/4532)
e-mail me at jamie DOT love AT clear DOT net DOT nz

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019