Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Help with system calls

Reply
Thread Tools

Help with system calls

 
 
december_beauty
Guest
Posts: n/a
 
      09-30-2005
I am writing a program which
a) accepts a command as a string
b) breaks the string into separate arguements
Eg: string : ls -l
argv[0]=ls arg[1]=-l
When I read the string using gets, it works fine. But when I use the
read(), it doesn't work.
I know how to parse the string and break them into individual
arguement, I am not happy with what I have coded it. Is there a
solution for this on the internet?
c) I need to exit when it presses ctrl-D. I don't know how to catch
ctrl-D. I tried a few things like, checking the first character of
the string with ascii value of ctrl-D, it's not working.
PLEASE HELP..

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      09-30-2005


december_beauty wrote On 09/30/05 12:13,:
> I am writing a program which
> a) accepts a command as a string
> b) breaks the string into separate arguements
> Eg: string : ls -l
> argv[0]=ls arg[1]=-l


If you're doing what I think you're doing, you probably
want argv[2[=NULL as well.

> When I read the string using gets, it works fine. But when I use the
> read(), it doesn't work.


First, see Question 12.23 in the comp.lang.c Frequently
Asked Questions (FAQ)

http://www.eskimo.com/~scs/C-faq/top.html

to learn why gets() is a bad idea, and why you should NEVER
use gets() for input from a source you don't control.

Second, there is no read() function in the Standard C
library.

Third, "it doesn't work" isn't a useful description of
your problem. It's about as helpful as my advice "Fix the
bug in your code."

> I know how to parse the string and break them into individual
> arguement, I am not happy with what I have coded it. Is there a
> solution for this on the internet?


A solution for what? For your unhappiness? You haven't
said why you're sad, nor what makes you happy, so I can't
offer any recommendation.

> c) I need to exit when it presses ctrl-D. I don't know how to catch
> ctrl-D. I tried a few things like, checking the first character of
> the string with ascii value of ctrl-D, it's not working.
> PLEASE HELP..


Keyboards and similar "interactive input" devices are
often given special treatment by operating systems, with the
result that what the program reads is not a simple record of
the keys the user pressed. This is usually a good thing: if
the user presses `l s - BS SPC - l ENTER' the program reads
"ls -l\n" and doesn't need to worry about all that intra-line
editing or about what code the ENTER key generates. Also,
most operating systems don't even generate characters for
some key combinations, instead treating them as "control
signals" of one kind or another.

On many systems, control-D is one such special keystroke.
Instead of generating a character that the program can read,
it tells the program that there is no more keyboard input to
be read: it synthesizes an "end-of-file" indication for a
device that inherently has no such thing. If you're using
such a system, there may be no way (or no "normal" way) to
read a control-D: instead, the attempt to read will yield
end-of-file. Perhaps the solution to your problem is not to
check for control-D at all, but to check for EOF.

(Note: Not all systems treat control-D this way. Some do
a similar thing with control-Z, and I've also seen control-A
used for the purpose. Some systems "ordinarly" use control-D
but can be adjusted to use some other key combination instead.)

--


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are system calls sometimes costlier than library calls? Richard Tobin C Programming 24 11-11-2007 08:52 AM
ods calls business object then method calls ta with output params andy6 ASP .Net 2 06-09-2006 01:54 AM
MoVoIP - FREE MOBILE Inetrnet Phone Calls - FREE Internet Phone Calls ubifone VOIP 0 07-29-2005 04:31 PM
How to determine available system calls on a Unix/Linux system markus C Programming 22 09-22-2004 10:32 PM
Sequence of constructor calls and destructor calls. Honne Gowda A C++ 2 10-31-2003 09:31 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57