473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with system calls

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.
d) Also does anyone know how to empty the arrays?
PLEASE HELP..

Nov 15 '05 #1
2 1469
december_beauty wrote on 30/09/05 :
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.
It's not. gets() is unsafe and deprecated. Use fgets() and read the
manual carefully (fgets() takes the '\n' when there is room enough).

But when I use the
read(), it doesn't work.
Dunno. Not a C-function. Why don't you stick to the standard ? If you
insist, you must ask a newsgroup that is related to programming on your
system.
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?
Because I know by heart the content of the two billions web pages on
the Net, my answer is yes.

Come on. Switch your brain on and don't ask silly questions... Google
is your friend...

BTW, why don't you post your attempts for a review ?
c) I need to exit when it presses ctrl-D. I don't know how to catch
ctrl-D.
Test the value returned by the input function. fgets() returns NULL on
end of reading.
I tried a few things like, checking the first character of
the string with ascii value of ctrl-D, it's not working.
Of course not. This is done by the lower level layers.
d) Also does anyone know how to empty the arrays?


You can't. Explain what you meant exactly with an example.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Mal nommer les choses c'est ajouter du malheur au
monde." -- Albert Camus.
Nov 15 '05 #2
"december_beauty" <km********@indiatimes-dot-com.no-spam.invalid> wrote
in message
news:43***********************@authen.white.readfr eenews.net...
I am writing a program which
b) breaks the string into separate arguements


No e.

--
Mabden
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Kenneth Lantrip | last post by:
trying to make something like this work... #include <stdio.h> int main (void) { #if defined UNIX printf("\n\n\n%s\n\n", "Program is running on a flavor of Unix."); #endif
5
by: markus | last post by:
Hi, I have a question that deals with the standard c library VS (Unix) system calls. The question is: which header files (and functions) are part of the C library and which header files (and...
4
by: Chronologic | last post by:
All, I have an issue I would like some expert help on. I understand, or so I believe, that C# does not support the concept of a "compile time macro". At least not in the sense I'm looking...
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
2
by: student | last post by:
Hi all, I'm having trouble with my datagrid, it is suppose to display a row from a table called "Calls" based on what is selected in the dropdownlist which displays the first and last name from...
1
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
21
by: omkar pangarkar | last post by:
Hi all, I have two simple hello world programs one using printf() and other using write() --prog 1-- #include<stdio.h> #include<stdlib.h> int main() { printf("Hello"); /* up to here...
0
by: akshaycjoshi | last post by:
I am reading a book which says Even though unboxed value types don't have a type object pointer, you can still call virtual methods (such as Equals, GetHashCode, or ToString) inherited or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.