Thread: Unix help system

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    41

    Unix help system

    Hi there, its me again... Now i know you are very anti do our homework for us, i understand this, and wholeheartedly agree, however, i need help with my homework.

    The long and short of it, is this program is designed to act as a short directory of help commands used within unix, the code below isn't complete, but where bits are missing there are labels and it compiles with no errors.

    Code:
    /*
    
    /* Interactive help system to train users into unix, using searches within strings and functions and all of it*/
    /*mitchell kent, 323786*/
    
    #include <stdio.h>
    #include <string.h>
    
    
    char command[6][5]={{"ls"},{"cd"},{"mv"},{"cp"},{"rm"},{"more"}};
    char description[6][42]={{"list files in a directory"},{"change directory"},{"rename or move files to another directory"},{"copy files"},{"delete files"},{"display the contents of files"}};
    
    
    
    /*this function searches for an inputted command and prints out the assc. description*/
    
    int lookup(void)
    {
    
    	int loop;
    	char comparison[5];
    
    	printf("Please enter command to look up");
    	printf("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n");
    
    	scanf("%s",comparison);
    
    	printf("%s",comparison);
    
    /* *******HERE IS THE PROBLEM****** */
    	for(loop=0;loop<=5;loop++)
    	{
    		if (comparison==command[loop])
    		{
    			printf("\nyour command was found:\n");
    			printf("%s - %s",command[loop],description[loop]);
    		}
    	}
    
    /* *** *** *** *** *** *** *** *** */
    
    
    	return 1;
    }
    
    /*this prog will find words within the description and print out all commands with that word in*/
    
    int findWID(void)
    {
    
    
    	return 1;
    }
    
    /*this function will display the list of commands available for this help system*/
    
    int disp_all_commands(void)
    {
    
    	int loop;
    
    	for(loop=0;loop<=5;loop++)
    	{
    		printf("%s",command[loop]);
    		printf("\n");
    	}
    
    	return 1;
    }
    
    /*this function prints out all commands and their descriptions*/
    
    int disp_all(void)
    {
    
    	int loop;
    
    	for(loop=0;loop<=5;loop++)
    	{
    		printf("%s - %s",command[loop],description[loop]);
    		printf("\n");
    	}
    
    
    
    	return 1;
    }
    
    
    /*this main function will be a simple switch clause, to choose the required function*/
    
    
    int main(void)
    {
    
    	printf("Welcome to the UNIX help system:\n");
    	printf("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n");
    	
    
    
    	disp_all();
    
    	printf("--------------------\n\n\n\n");
    
    	disp_all_commands();
    
    	printf("--------------------\n\n\n\n");
    
    	lookup(); /* the function in question*/
    	
    
    	
    		
    	return 0;
    
    }
    */

    basically, the function in question (up the top, lookup() ) as far as i know should work. though i think there is a function that compares strings in the string header file. i get no errors but the if statement found below

    Code:
    /*
    
    	for(loop=0;loop<=5;loop++)
    	{
    		if (comparison==command[loop])
    		{
    			printf("\nyour command was found:\n");
    			printf("%s - %s",command[loop],description[loop]);
    		}
    	}
    
    */
    should work, right?

    any help?

    cheers

    Mitch
    ~~~~~~~~~~
    Mitchell Kent
    07782383326
    [email protected]
    ~~~~~~~~~~

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    41

    Apologies

    I have found the tutorials now, and now know how to use strcmp, i saw it ages ago and got scared of the pointers, but have ignored them and its running fine so far!

    From now on I'll try not to give a running commentary of my work

    Mitch
    ~~~~~~~~~~
    Mitchell Kent
    07782383326
    [email protected]
    ~~~~~~~~~~

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You can't compare the contents of two strings directly.

    What the if (comparison==command[loop]) is doing is comparing the addresses of the two strings to see if they are the same.

    Also it might be helpful to put the contents of the 2d array on their own line so you don't have the horizontal mess you have now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 07:38 AM
  2. School Mini-Project on C/C++ (Need Your Help)..
    By EazTerence in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2005, 01:08 AM
  3. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  4. question about open file in unix system
    By wu7up in forum C Programming
    Replies: 6
    Last Post: 03-13-2003, 06:20 AM
  5. AIX unix system script (need help)
    By Liam Battle in forum Linux Programming
    Replies: 4
    Last Post: 02-10-2002, 05:34 PM