The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
echo debasis.mishra Shell Programming and Scripting 0 03-28-2006 12:35 AM
How to set echo on siegfried Shell Programming and Scripting 1 11-18-2005 01:56 AM
What does echo ^[[r do? hamsasal UNIX for Advanced & Expert Users 1 07-24-2005 01:14 PM
echo with \n whatisthis UNIX for Dummies Questions & Answers 3 05-18-2005 10:59 AM
echo ????? nguda UNIX for Dummies Questions & Answers 1 06-30-2003 04:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2002
bb00y bb00y is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 25
echo help

i found this code in the book but was unable to execute it.
/*myecho -- echo command line arguments */

main(int argc, char **argv)
{
while(--argc > 0)
printf("%s ", *++argv);
printf("\n");
}

this is another program that would invoke the one above

char * const argin[] = {"myecho", "hello", "world", (char *)0};

execvp(argin[0], argin);

the output suppose to display "hello world"

i tried putting the bottom portion in another main function, but it did not work.
help please. thank you
  #2 (permalink)  
Old 10-02-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
The code you posted is legal although it is not very well written. I too put the last fragment inside a main function.

As written, the code assumes that the myecho program will be found on the PATH. Since that would not be true in my case, I changed the {"myecho", to read {"./myecho",

Other than the PATH search issue, I don't see anything wrong enough to keep it from running.

What system are you using? What compiler? What result do you get when you try this?
  #3 (permalink)  
Old 10-02-2002
bb00y bb00y is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 25
i'm using gcc.
compiling on a remote computer using ssh.
the first main program i saved it as myecho.c
the second main program(the bottom portion) i called it caller.c
when i gcc caller.c then a.out, i didn't get anything. It's like it's not calling anything.
o...and ./myecho doesn't make any difference
thanks
  #4 (permalink)  
Old 10-02-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Works fine with gcc, too. Do:
gcc myecho.c -o myecho
./myecho test one two three
gcc caller.c -o caller
./caller
uname -a

and post the results.
  #5 (permalink)  
Old 10-02-2002
bb00y bb00y is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 25
a ha...i found the problem. instead of "myecho" i typed it as "myecho.c".
hey thanks alot for taking the time to answer.
by the way, i didn't run it as ./ i jut runned it regularly and it still worked. instead of ./a.out i just simply used a.out and it run just fine. what's the point of using ./ ?
thanks
  #6 (permalink)  
Old 10-02-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
That must mean that "." is in your PATH, or you are in a directory that is in your path. "./program" will execute the "program" in your current directory.

Many people will remove "." (the current directory) from their PATH variable for security reasons, and others will do it just to be safe. Many normal users can leave "." in their PATH, as long as they're cautious of where they are and what they're executing.

Also, if you name a program "test", you'll want to give a full path to it, since "test" already exists in many shells as a builtin command, or as a system binary. In that case executing "test" and executing "./test" will be two different programs.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0