Need some help with this...


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 29  
For some reason, the array paths is getting destroyed after alias does its job. Atleast thats what I observed.. My alias code is something like this:

Code:
if(aliasoption == 1)  {
            strcpy(buff, "csh -c \"alias ");
            strcat(buff, command);
            strcat(buff, wordclose);
            /*printf("%s",final);*/
            fp = popen(buff,"r");
            if(fp == NULL)
            {
                  printf("Handle Error");
            }
            /*else printf("Opened\n");
            printf("You asked for an alias\n");*/
            printf("alias %s= ",command);
            while(fgets(buff,sizeof(buff),fp) != NULL)
                  printf("%s",buff);
            pclose(fp);
            printf("\nNew Line");
        }

Edit: I tried defining paths[] as a Global Variable but no luck...

Last edited by Legend986; 10-01-2007 at 07:16 PM..
# 30  
Anyways, I got it working by pasting the same code somewhere in the alias code. Well, though I'm not sure why it happened, it does work now...
# 31  
Quote:
Originally Posted by Legend986
Anyways, I got it working by pasting the same code somewhere in the alias code. Well, though I'm not sure why it happened, it does work now...
The trick now is to go through what you have written and see what is redundent or duplicated.
# 32  
I haven't done anything actually. I just copied the text under the if conditional loop that actually performs the check into the alias loop and initiated the print command before the alias command was put to work...
# 33  
I am seeing a type of display I mean if the path is long, unix is substituting a '~'. How would I do that here? For example, if I find a command in a path, how would I substitute a tilde in the output?
# 34  
Quote:
Originally Posted by Legend986
I am seeing a type of display I mean if the path is long, unix is substituting a '~'. How would I do that here? For example, if I find a command in a path, how would I substitute a tilde in the output?
Over egging the pudding I think.

~ is normally short-hand for $HOME.

You would have to look at what you were going to print, decide if it's too long, if so decide where to truncate, then print your truncated string and truncation indicator.
# 35  
Yup. Got it Smilie Thanks
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #624
Difficulty: Medium
The continue statement is used in Python to skip the rest of the statements in the current loop block and to continue to the next iteration of the loop.
True or False?

Featured Tech Videos