Here’s my innocent-looking program
int main(int argc, char* argv[])
{
if(argc < 3)
{
printf("Sorry");
return 0;
}
char key[]= "45WPbZNljDN6CUCUU6ga";
FILE* inpFile = fopen(argv[1],"r");
FILE* outFile = fopen(argv[2],"w");
if(!inpFile || !outFile)
{
printf("oops");
return 0;
}
enc(inpFile,outFile,key);
fclose(inpFile);
fclose(outFile);
}
enc() is defined elsewhere but it’s not a problem. When I try to compile using the VS2010 command prompt, everything goes berserk. However, when I remove the argument-check block, it compiles fine.
int main(int argc, char* argv[])
{
char key[]= "45WPbZNljDN6CUCUU6ga";
FILE* inpFile = fopen(argv[1],"r");
FILE* outFile = fopen(argv[2],"w");
if(!inpFile || !outFile)
{
printf("oops");
return 0;
}
enc(inpFile,outFile,key);
fclose(inpFile);
fclose(outFile);
}
Any ideas?
If it is compiled as a C program (.c extension with VS2010), it is not valid to declare variables after executable statements. You would need to move the declarations (
key,inpFile, andoutFile) all up to the front ofmain(prior to the firstifstatement).