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);
}