[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[LCP]Char Comparisons?



All,

Im having some trouble getting a program to work as expected, i have a
simple shell interface, and when a command is entered, it should execute
a function.
Now the problem i believe is the if statement, as the comparison is
between a char and a regular text string. I know it is getting the
string entered at the prompt in the buffer, as indicated by the printf
just before the if statement, in the main loop.

Here is the code...

#include <stdio.h>

static void myexit(int sig) {
    exit(0);
}

void load(void) {

    char cpubuff[256];
    FILE *fp;
    
    fp = fopen("/proc/loadavg","r");
    fgets(cpubuff,256,fp);
    fclose(fp);    	
    printf("%s",&cpubuff);
}

int usage(void) {
    printf("You Git. Read the source!\n");
    return 1;
}

int main(int argc, char *argv[]) {

    char buf[256];

    for(;;) {
        printf("> ");
        scanf("%s",&buf);

        printf("%s\n",buf);
	
	if(buf=="load") {
	    load();
	} else {
	    usage();
	}
    }

    return 0;
}

TIA, any help is great :)


Regards,

James Mclean

"Increased knowledge will help you now.  
 Have a mate's phone bugged."
		-- /usr/games/fortune