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

Re: [LCP]Char Comparisons?



Its better to learn some C programming then come to
unix internals.
Try out kerningham and ritchie.

devraj



On Thu, 29 Aug 2002 James Mclean wrote :
>
>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
>
>_______________________________________________
>This is the Linux C Programming List
>:  http://lists.linux.org.au/listinfo/linuxcprogramming List