Thread: Newbie - error in code

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    Newbie - error in code

    I downloaded this code, and it won't conpile in either DJGPP, or Bloodshed, please help!

    Code:
    # include <stdlib.h>
    # include <conio.h>
    # include <stdio.h>
    
    void main(int argc,char *argv[])
    {
    	if(argc<=2)
    	{ printf("Usage :.. <sourcefile(.exe)> <strippedfilename> <headerfile>");
    	  exit(0);
    	}
    
    	/* The File Handles */
    
    	FILE *srcFile , *dstFile , *hdrFile;
    
    	printf("Opening source file %s",argv[1]);
    
    	if((srcFile = fopen(argv[1],"rb"))==NULL)
    	{ printf("\nfatal-error: file (%s) not found. exiting..",argv[1]);
    	  exit(1);
    	}
    
    	printf("\nCreating destination files %s.bin and header.bin",argv[1]);
    
    	if((dstFile = fopen(argv[2],"wb"))==NULL)
    	{ printf("\nfatal-error: output file (%s) could not be created. exiting..",argv[1]);
    	  exit(1);
    	}
    
    	if((hdrFile = fopen(argv[3],"wb"))==NULL)
    	{ printf("\nfatal-error : header output could not be created.");
    	  exit(1);
    	}
    
    	printf("\nStripping EXE header..");
    
    	char* buffer = new char[512];
    
    	fread (buffer,512,sizeof(char),srcFile);
    	fwrite(buffer,sizeof(char),512,hdrFile);
    
    
    	fclose(hdrFile);
    
    	printf("\nWriting rest of the binary to %s",argv[2]);
    
    	while(!feof(srcFile))
    	{ fputc(fgetc(srcFile),dstFile); }
    
    	printf("\nDone.");
    
    	fclose(dstFile);
    	fclose(srcFile);
    
    	EXIT_SUCCESS;
    }

  2. #2
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    The errors are...?

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    The errors

    Sorry, the errors are:
    Code:
    stripexe.cpp: 19: error: 'main' must return 'int'

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > void main(int argc,char *argv[])
    Oh look - main returns void here

    Perhaps you should take the hint and write
    int main(int argc,char *argv[])

    Also, you need to add a
    return 0;
    to the end of main

    3. while(!feof(srcFile))
    This is in the FAQ
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  3. newbie reading code
    By franziss in forum C++ Programming
    Replies: 9
    Last Post: 08-25-2005, 12:18 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Newbie - MFC code from a book in VC++.Net
    By Guardian in forum Windows Programming
    Replies: 2
    Last Post: 04-27-2002, 07:17 PM