Reputation: 2689
Can someone please tell me why this code will not work? It does compile. When I type decrypt as the argv[1] argument in the command line, it still gives me the else output. i.e. argv[1] is not satisfied even though it should be. This is a work in progress so ignore the other code
if ((argv[1] == "decrypt"))
{
printf("Decrypting...\n");
c = getc(fp1);
if (c != EOF)
{
fread(inputbuffer, sizeof(char), 50 , fp1);
printf("%s", inputbuffer);
/*while(inputbuffer[i]!=EOF)
{
fputc((inputbuffer[i] / 2) - 5, fp2);
}*/
}
}
else {printf("argv not working");}
Upvotes: 0
Views: 515
Reputation:
You need to use strcmp()
to compare strings:
if ((strcmp(argv[1], "decrypt") == 0)
What you are comparing are the two memory addresses for the different strings, which are stored in different locations. Doing so essentially looks like this:
if(0x00403064 == 0x002D316A) // Two memory locations { printf("Yes, equal"); }
Upvotes: 11