Visit Our UNIX and Linux User Community


Need some help with this...


 
Thread Tools Search this Thread
Top Forums Programming Need some help with this...
# 29  
Old 10-01-2007
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  
Old 10-01-2007
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  
Old 10-01-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
Yup. Got it Smilie Thanks

Previous Thread | Next Thread
Test Your Knowledge in Computers #575
Difficulty: Medium
If a program has poor memory management and fails to deallocate memory when it is no longer needed, the memory will not leak.
True or False?

Featured Tech Videos