For some reason, when I enter in pwd, it tries to execute it instead of executing "cd", like I told it to. What is going on here?Code:if(input == "pwd") { system("cd"); } else { system(input); }
For some reason, when I enter in pwd, it tries to execute it instead of executing "cd", like I told it to. What is going on here?Code:if(input == "pwd") { system("cd"); } else { system(input); }
There you go.Code:if( strcmp( foo, bar ) == 0 ) printf( "We have a match!" ); else printf( "Variables 'foo' and 'bar' are different." );
Quzah.
Hope is the first step on the road to disappointment.
just like quzah said.
you need to use strcmp from the <string.h> library to compare strings.
if strcmp returns 0 then they are a match
if strcmp returns 1 then first arg greater then second arg
if strcmp returns -1 then first arg is less then second arg
cheers
there are only 10 people in the world, those who know binary and those who dont
So...
Code:if(strcmp(input,"pwd") == 0) { system("cd"); } else { system(input); }
the if always fails?
are you sure you getting "pwd" back and not "pwd\n"?
Thank you very much, mart_man! The program works now!
You could always read the FAQ . It'll answer some of your questions for you...
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]