Something screwy going on here...
OK, Here is a program that was working perfectly fine a few days ago, but has suddenly decided to begin depositing 56MB files on my computer (at least, that's how far it gets before I shut it down). It doesn't give any errors on lcc-win, and I wouldn't have though it was so complex that the error would just pop up.
So you know, it's a command-line hex <=> ASCII converter. It works through typecasting, because I figured I'd be slack and not bother with the union.
Here's the code:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) //Command Argument Format: hex <inputfile> <outputfile> {-d}
{
//Manual Output
if(argc == 1)
{
printf("Format of Command Line Hex: hex <inputfile> <outputfile> {-d}\n\n");
printf("<inputfile> File to be read from\n");
printf("<outputfile> File to read De/Hexed output to\n");
printf("{-d} De-hex code\n");
exit(4);
}
//Declaration of Variables
FILE * in = fopen(argv[1], "r");
FILE * out = fopen(argv[2], "w");
unsigned short int hex;
char letter;
//Input File Check
if(in == NULL)
{
fprintf(stderr, "Error - Input file %s not found", argv[1]);
exit(1);
}
//Output File Check
if(out == NULL)
{
fprintf(stderr, "Error - Output file %s not available", argv[2]);
exit(2);
}
if(argc == 4)
{
//De-hexification code
if(strcmp("-d", argv[3]) == 0)
{
while(fscanf(in, "%hX ", &hex) != EOF)
{
letter = hex;
fprintf(out, "%c", letter);
}
fclose(in);
fclose(out);
return 0;
}
else
{
fprintf(stderr, "Error - Unrecognised switch");
fclose(in);
fclose(out);
exit(5);
}
}
//Hexification code
else
{
while(fscanf(in, "%c", &letter) != EOF)
{
hex = letter;
fprintf(out, "%2hX ", hex);
}
fclose(in);
fclose(out);
return 0;
}
return 0;
}