Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 14:42

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: I think I'm a noob.
PostPosted: 22 Jun 2009 22:18 

Joined: 22 Jun 2009 22:12
Posts: 1
I haven't being programming in C for very long (recently learned about argc+argv to give you an idea of how new) and I use linux.

When I run the gcc, which I have used for a while, and understand how to compile simple programs like the one I'm doing, I have gotten to the point that I get no errors or warnings. Yet, after compiling, I run the program from the command line, and it does nothing. No errors, no text whatsoever. It just gives me a new line for a command. It really ticks me off because I don't have a clue what I need to fix.

If anyone could give me any help on what to do, I would really appreciate it!

Code:
#include <stdio.h>
#include <stdlib.h>

#ifdef WIN32
#define WINDOWS 1
#else
#define WINDOWS 0
#endif

#define MAJVER   0
#define MINVER   0
#define BUILD   1

#define DO_SWITCH(count, args) (count>1 ? args[1][0]=='-' ? args[1][1] : 0 : 0)


// Functions
void shell(char *cmd);
void getfilenames(void);
void encode(void);
void decode(void);
void version(void);

// Globals
char   *infilename,
   *outfilename;
char   *app_name;

int main(int argc, char **argv) {
   app_name=argv[0];
   // if there were no args given, start interactive mode
   if(argc==0) {
      shell("clearscreen");
      version();
      getfilenames();
   }
   /*************************************************************************
   * if there were args given, use the second and third args for the in and *
   * out, resp.                                                             *
   *************************************************************************/
   else {
      infilename=argv[2];
      outfilename=argv[3];
      DO_SWITCH(argc, argv);
      switch(DO_SWITCH(argc, argv)) {
         case 'e': encode();
         case 'd': decode();
      }
   }
   return 0;
}
void getfilenames(void) {
   FILE   *exist;

   printf("\n\nInput filename: ");
   scanf("%s", infilename);
   exist=fopen(infilename,"rb");
   if(!exist) {
      printf("\n%s: Input file read error\n", app_name);
      getfilenames();
   }
   printf("\nOutput filename: ");
   scanf("%s", outfilename);
}   

void encode(void) {
   FILE   *in_bin,
      *out_hex;

   printf("\n\nEncoding nothing-ness\n\n");
}

void decode(void) {
   FILE   *in_hex,
      *out_bin;

   printf("\n\nDecoding nothing-ness\n\n");
}

void shell(char *cmd) {
   if(cmd=="clearscreen") {
      if(WINDOWS) system("cls");
      if(!WINDOWS) system("clear");
   }
}

void version(void) {
   printf("%d.%d.%d", MAJVER, MINVER, BUILD);
}


Top
 Profile  
 
 
 Post subject: Re: I think I'm a noob.
PostPosted: 23 Jun 2009 17:28 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
I can give you the best suggestion.
compile the source code with the -ggdb options (and do NOT use -s or the strip command on the executable) and then run it with gdb.
the fact that you receive no output probably means that the tool is crashed so with gdb you can see the exact line where the problem happened and so you can fix it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: