By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

some problems of C scripts in Unix

P: n/a
Could any answer following questions as many as you can.

ii) Write a C shell script convertmin which will read in a number, thought
of as representing minutes, and print out the number of hours/minutes it
represents so:
[Note: you are required to check exception cases: such as negative number,
whether the input is numeric,etc]

$ convertmin
Enter a number of minutes:
128
Result
128 minutes is 2 hours and 8 minutes

iii) Write a C shell script in2ftcm which uses arithmetic expansion to
convert from inches to meters and centimetres, rounded down to the nearest
whole number of centimetres. Input should be a whole number of inches, and
you may assume.
Explain your algorithm to determine the inches from the centimetres input.

iv) Write a C shell script , test your script on your ucourse server, called
greetings which will print out one of Good morning, Good afternoon or Good
evening depending on the time of day. [Hints: You can use the output of date
and pattern matching]. (

Question 3
In C program compilation process, you have seen a lot of terminologies such
as preprocessor,
complier, object code, linker, and executable file. Describe the functions
of these
terms in a C program compilation process.

Question 4

(a) Write a C shell script which will read the first 250 lines of a given
text file and store it into a new file. You can assume the given file has
more than 500 text lines.

(b) Write a C program which will read the first 250 lines of a given text
file and store it into a
new file. You can assume the given file has more than 500 text lines.
You are required to create a new file and keep
the original file unchanged.]

Question 5
In this question you will need to write a simple network related C program.
Follow the
instructions as much as you can and if you are in doubt consult your tutor
or post your query
in your group BBS.
Background: On unix system, one quick way to find out who has accessed the
system is to
use the ¡¥last¡¦ command . For example, you can find out the last 500
entries using
$last ¡V500
Or you can save the output onto a file using the redirect command
$last ¡V500 > last500.log
WARNING, do not simply type the last command without the ¡V500 option,
otherwise
your command will use up a lot of CPU resource and slow your programming
work!
Expected outcome:
Create the last500.log file and then write a C program to read the
last500.log file. Your
program should then delete all the entries that contain ouhk¡¦. You should
rename the output
file as non-ou.log.


Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"kamkwokho" <ka*******@hkbn.net> wrote in message
news:be**********@news.ctimail.com...
Could any answer following questions as many as you can.

ii) Write a C shell script convertmin which will read in a number, thought
of as representing minutes, and print out the number of hours/minutes it
represents so:
[Note: you are required to check exception cases: such as negative number,
whether the input is numeric,etc]

$ convertmin
Enter a number of minutes:
128
Result
128 minutes is 2 hours and 8 minutes

iii) Write a C shell script in2ftcm which uses arithmetic expansion to
convert from inches to meters and centimetres, rounded down to the nearest
whole number of centimetres. Input should be a whole number of inches, and
you may assume.
Explain your algorithm to determine the inches from the centimetres input.

iv) Write a C shell script , test your script on your ucourse server, called greetings which will print out one of Good morning, Good afternoon or Good
evening depending on the time of day. [Hints: You can use the output of date and pattern matching]. (

Question 3
In C program compilation process, you have seen a lot of terminologies such as preprocessor,
complier, object code, linker, and executable file. Describe the functions
of these
terms in a C program compilation process.

Question 4

(a) Write a C shell script which will read the first 250 lines of a given
text file and store it into a new file. You can assume the given file has
more than 500 text lines.

(b) Write a C program which will read the first 250 lines of a given text
file and store it into a
new file. You can assume the given file has more than 500 text lines.
You are required to create a new file and keep
the original file unchanged.]

Question 5
In this question you will need to write a simple network related C program. Follow the
instructions as much as you can and if you are in doubt consult your tutor
or post your query
in your group BBS.
Background: On unix system, one quick way to find out who has accessed the
system is to
use the ¡¥last¡¦ command . For example, you can find out the last 500
entries using
$last ¡V500
Or you can save the output onto a file using the redirect command
$last ¡V500 > last500.log
WARNING, do not simply type the last command without the ¡V500 option,
otherwise
your command will use up a lot of CPU resource and slow your programming
work!
Expected outcome:
Create the last500.log file and then write a C program to read the
last500.log file. Your
program should then delete all the entries that contain ouhk¡¦. You should
rename the output
file as non-ou.log.


Yes I could answer some of the following questions, how many, say 4 maybe 5.
Why do you want to know?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.497 / Virus Database: 296 - Release Date: 04/07/03
Nov 13 '05 #2

P: n/a

"kamkwokho" <ka*******@hkbn.net> wrote in message

Could any answer following questions as many as you can.
You'll have to do your own homework. However I'll give you some pointers.
ii) Write a C shell script convertmin which will read in a number, thought
of as representing minutes, and print out the number of hours/minutes it
represents so:
[Note: you are required to check exception cases: such as negative
number, whether the input is numeric,etc]
The last requirement makes this quite difficult. You need to write a
function
myisinteger(char *str) to check that input genuinely is an integer.
Apart from that, it is simply a case of input a number, use the division and
modulus operators to convert to hours, an output it.
iii) Write a C shell script in2ftcm which uses arithmetic expansion to
convert from inches to meters and centimetres, rounded down to the
nearest whole number of centimetres. Input should be a whole number of
inches, and you may assume.
Explain your algorithm to determine the inches from the centimetres input.
The tricky thing here is that an inch is not a whole number of centimeters.
Also, C integer arithmetic rounds off. What I advise you do is to convert
all quantities to doubles, and not to throw away any precison until you come
to output.
iv) Write a C shell script , test your script on your ucourse server, called greetings which will print out one of Good morning, Good afternoon or
Good evening depending on the time of day. [Hints: You can use the output
of date and pattern matching].
Look up the time functions. Esp localtime().
Question 3
In C program compilation process, you have seen a lot of terminologies
such as preprocessor, complier, object code, linker, and executable file.
Describe the functions of these terms in a C program compilation process.
This you do need to know. The preprocessor essentially does word-processing
commands on C source. Thus you can #include files, define constants like PI,
conditionally exclude blocks of code, and define macros.
The compiler then takes the pre-processed C source and converts it to object
code, which is essentially machine-language instructions, but with some bits
of cleverness to allow the object files to be linked. The linker is what
produces the final executable, from one or more object files. Finally the
executable is a native machine-language program. There may be no way of
telling it was originally produced from a C program.
Question 4

(a) Write a C shell script which will read the first 250 lines of a given
text file and store it into a new file. You can assume the given file has
more than 500 text lines.
This is easy. Just use fgets() to read in 250 lines.
(b) Write a C program which will read the first 250 lines of a given text
file and store it into a
new file. You can assume the given file has more than 500 text lines.
You are required to create a new file and keep
the original file unchanged.]
I can't see the difference between this and question a), unless there's some
difference between C program and C shell script which I am unaware of.
Question 5
In this question you will need to write a simple network related C program.

This is beyond the scope of this ng, since networking is platform-dependent.
You will have to try unix.programmer for help on this one.
Nov 13 '05 #3

P: n/a

"Malcolm" <ma*****@55bank.freeserve.co.uk> wrote in message
news:be**********@newsg1.svr.pol.co.uk...

"kamkwokho" <ka*******@hkbn.net> wrote in message
<snip> Question 4

(a) Write a C shell script which will read the first 250 lines of a given text file and store it into a new file. You can assume the given file has more than 500 text lines.
This is easy. Just use fgets() to read in 250 lines.

(b) Write a C program which will read the first 250 lines of a given text file and store it into a
new file. You can assume the given file has more than 500 text lines.
You are required to create a new file and keep
the original file unchanged.]

I can't see the difference between this and question a), unless there's

some difference between C program and C shell script which I am unaware of.


A C program is a compiled program written in C. A C shell script (more
appropriately written "C-Shell script" or just "csh script") is an
interpretted program written in the UNIX C-Shell (csh) scripting language.

OP - You'd get better information on csh scripting at comp.unix.shell, but
at least attempt the homework yourself first or you're unlikely to get a
positive response.

Ed.
Nov 13 '05 #4

P: n/a
kamkwokho wrote:
Could any answer following questions as many as you can.

... [clip] ...

Probably all of them (didn't bother to read them) but we won't do your
homework here.

P.S. also the ones about the unix csh are off-topic anyway.

-- Nuclear / the Lab --

Nov 13 '05 #5

P: n/a
Ed Morton wrote:

<snip>

A C program is a compiled program written in C.


http://eic.sourceforge.net/ :-)

<snip>

--
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
Nov 13 '05 #6

P: n/a
On Sun, 6 Jul 2003 17:55:45 +0100, in comp.lang.c , "Malcolm"
<ma*****@55bank.freeserve.co.uk> wrote:

(b) Write a C program which will read the first 250 lines of a given text
file and store it into a
new file. You can assume the given file has more than 500 text lines.
You are required to create a new file and keep
the original file unchanged.]

I can't see the difference between this and question a), unless there's some
difference between C program and C shell script which I am unaware of.


C shell is a unix command processor.
C is not a unix command processor.
Apart from that, the questions are identical.

--
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 =---
Nov 13 '05 #7

P: n/a
On Sun, 6 Jul 2003 23:21:20 +0800,
kamkwokho <ka*******@hkbn.net> wrote
in Msg. <be**********@news.ctimail.com>
Could any answer following questions as many as you can.


Yup.

--
"With me is nothing wrong! And with you?" (from r.a.m.p)
Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.