473,394 Members | 1,752 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,394 software developers and data experts.

some problems of C scripts in Unix

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
7 3517

"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

"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

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Florian Lindner | last post by:
Hello, I've a scripts that allows limited manipulation of a database to users. This script of course needs to save a password for the database connection. The users, on the other hand need read...
9
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash...
4
by: Ringo Langly | last post by:
Hi all, I'm a seasoned web programmer, but I've never touched XSLT. It's always been one of those acronyms I've never needed to educate myself on. Now... we're working with a web content...
8
by: Jan Danielsson | last post by:
Hello all, How do I make a python script actually a _python_ in unix:ish environments? I know about adding: #!/bin/sh ..as the first row in a shell script, but when I installed python on...
2
by: Ryan Gaffuri | last post by:
Ill also need to return values. How do I do this? Im using GNU on solaris 2.8 with korn shell scripts?
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
46
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented...
7
by: JahMic | last post by:
I'm having a problem with exec on my hosting server. Unfortunately, the hosting support seems to be anything but helpful. The following works fine on my localhost: <?php $MaskData =...
7
by: Yansky | last post by:
I asked my hosting company if they would upgrade Python on my server to the latest version. They responded with: "Sorry no. We tend to stick with what comes packaged with the unix distribution...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.