I need to do this exercise, but am having problems.
I need to write a program that firstly, sleeps for 5 seconds, then reads
a line of input from file descriptor 0 and then writes the line back to
file descriptor 1.
Apparrantly, this program would block forever unless you type a line of
text on the keyboard, but I can't get a working program to try.
Next, this program needs to be modified so that it would write its input
from file descriptor 0 to file descriptor 1 IF there is an input line
from the keyboard. Otherwise it should report no input and terminate.
Can anyone help me with this please? I've spent far too long on it
already, and it's holding me up from moving to the next exercise... 8 3592
J Peterman writes: I need to do this exercise, but am having problems.
I need to write a program that firstly, sleeps for 5 seconds, then reads a line of input from file descriptor 0 and then writes the line back to file descriptor 1.
Apparrantly, this program would block forever unless you type a line of text on the keyboard, but I can't get a working program to try.
Next, this program needs to be modified so that it would write its input from file descriptor 0 to file descriptor 1 IF there is an input line from the keyboard. Otherwise it should report no input and terminate.
Can anyone help me with this please? I've spent far too long on it already, and it's holding me up from moving to the next exercise...
Try the following buzzwords on google and also on google advanced groups:
conio curses ncurses kbhit
If that doesn't work post to a group that talks about *your* compiler, not
the generic language which is what this group is.
J Peterman wrote: I need to do this exercise, but am having problems.
^^^^^^^^^^^^^^^^^^^^^^^^^^ I need to write a program that firstly, sleeps for 5 seconds, then reads
^^^^^^^^^^^^^^^^^^^^^^^^^ a line of input from file descriptor 0 and then writes the line back to file descriptor 1.
(Note the marked text, above.)
This is not a do-my-homework forum. If you have a specific question about
ISO C, feel free to ask it here. If your ISO C code doesn't work, show it
to us and perhaps we can help you fix it.
Note that C provides no idle wait routine as standard, nor does it deal with
file descriptors. The closest you can get in standard C is a busy loop with
time() for the waiting, and stream pointers (FILE *) for the I/O.
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
> osmium wrote: Try the following buzzwords on google and also on google advanced groups:
conio curses ncurses kbhit
If that doesn't work post to a group that talks about *your* compiler, not the generic language which is what this group is.
Sorry, I thought this group was for programming ic C....which is what I
am trying to write this program in. I'm afraid I don't know enough of
what is going on to know where I *should* be posting.
Richard Heathfield wrote: J Peterman wrote:
I need to do this exercise, but am having problems. ^^^^^^^^^^^^^^^^^^^^^^^^^^
I need to write a program that firstly, sleeps for 5 seconds, then reads
^^^^^^^^^^^^^^^^^^^^^^^^^
a line of input from file descriptor 0 and then writes the line back to file descriptor 1.
(Note the marked text, above.)
This is not a do-my-homework forum. If you have a specific question about ISO C, feel free to ask it here. If your ISO C code doesn't work, show it to us and perhaps we can help you fix it.
While I don't expect anyone to do my homework for me, I figured it
wasn't worth posting my own code, mainly because I have so little of it.
I just figured it was an easy enough exercise for someone to do in about
2min...That way, I could take note and move on.
For what it's worth, here is what I have...
/* begin code */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
main()
{
int nread;
char buf[100];
pid_t pid;
pid = fork();
if(pid ==0)
{
sleep(5);
nread = read(0, buf, 100);
// write(1, buf, nread);
printf("DEBUG: Value of nread = %d\n",nread);
}
return(0);
}
/* end code */
I'm trying to implement read, but it keeps giving me an error...Once I
get that sorted, I think I need to implement the write line.
Any help is appreciated...Thanks
Note that C provides no idle wait routine as standard, nor does it deal with file descriptors. The closest you can get in standard C is a busy loop with time() for the waiting, and stream pointers (FILE *) for the I/O.
J Peterman <J@nospam.please> scribbled the following: > osmium wrote: Try the following buzzwords on google and also on google advanced groups:
conio curses ncurses kbhit
If that doesn't work post to a group that talks about *your* compiler, not the generic language which is what this group is.
Sorry, I thought this group was for programming ic C....which is what I am trying to write this program in. I'm afraid I don't know enough of what is going on to know where I *should* be posting.
This group IS for programming C. C is a programming language, not a Unix
or a Window OS interface. C has been standardised by ISO, the
International Organisation for Standardisation, and conio, curses,
ncurses and kbhit, amongst a lot of other things, fall outside the scope
of that standard. Why? Because they are not even needed on all
platforms, and to give implementors more freedom in how they design the
interface to their OS.
Come to think of it, it's possible to write an industry-strength
application costing millions of dollars without ever needing to clear
the screen, or read directly from the keyboard! How does this sound?
As to which groups you should be posting in, that depends on your OS.
Is it Unix? Then post to comp.unix.programmer. Is it Windows? Then post
to comp.os.ms-windows.programmer.misc or
comp.os.ms-windows.programmer.win32.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
- Teemu Kerola
J Peterman wrote: While I don't expect anyone to do my homework for me, I figured it wasn't worth posting my own code, mainly because I have so little of it. I just figured it was an easy enough exercise for someone to do in about 2min...That way, I could take note and move on.
The main problem is that to do what you want to do will require extensions
to the base language, those extensions will be provided by *your* compiler,
not a generic ISO C compiler. Thus my hint to post to a newsgroup that
matches your compiler.
.. For what it's worth, here is what I have...
/* begin code */
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h>
Sevrral of those are not standard C headers. So even if it worked, it falls
outside the domain of this newsgroup.
This looks like a question for comp.unix.programmer.
On Mon, 13 Oct 2003 15:46:23 +0800, in comp.lang.c , J Peterman
<J@Nospam.please> wrote: While I don't expect anyone to do my homework for me, I figured it wasn't worth posting my own code, mainly because I have so little of it. I just figured it was an easy enough exercise for someone to do in about 2min...That way, I could take note and move on.
For what it's worth, here is what I have...
/* begin code */
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h>
Now we know you're doing this on a variant of unix. So you need to ask
in comp.unix.programmer. read(), fork() and pids are offtopic here
since tehy're platform-specific.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tomislav Lepusic |
last post by:
Hello,
I don't know if this is the right group (I'm more in Perl, know nothing
about Python), so if you can help me thanks, if not, sorry to bother you.
I'm working on my student project and...
|
by: titi |
last post by:
Question
The road and traffic authority for a small country currently uses a
system to store information about all 'currently' licensed drivers.
A licensed driver has the following info stored...
|
by: Bonj |
last post by:
I've been following a socket programming tutorial to make a simple TCP
communication program, seemingly without hitches, it appears to work fine.
However the structure of it is to have a server...
|
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help...
|
by: Trvl Orm |
last post by:
I am working with 2 frames, Left and Right and the main code is in the
left frame, which has been attached.
Can someone please help me with this code. I am new to JavaScript and
can't figure it...
|
by: TrvlOrm |
last post by:
OK. After much playing around, I managed to get my frame page this
far.. see code below.
BUT...there are still errors with it, and what I would like to have
happened is this:
1) On the Left...
|
by: MrG{DRGN} |
last post by:
Hello,
I've been saving up to buy myself some C programming texts so that I might
learn, and my wife surprised me by getting something off eBay for a fairly
cheap price. Unfortunately the book...
|
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...
|
by: DJ Dharme |
last post by:
Hi all,
I am writing a multi-threaded application in c++ running on
solaris. I have a file which is updated by a single thread by
appending data into the file and at same time the other threads...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |