some problems of C scripts in Unix

K

kamkwokho

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.
 
J

Jason Bennett

kamkwokho said:
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?
 
M

Malcolm

kamkwokho said:
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.
 
E

Ed Morton

Malcolm said:
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.
 
J

John Tsiombikas (Nuclear / the Lab)

kamkwokho said:
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 --
 
M

Mark McIntyre

(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Scripts 3
Help with Visual Lightbox: Scripts 2
Big problem I need to solve with some unix utils 1
C exercise 1
Bash scripts for web apps 1
Scipy install Problems 1
C Programming functions 2
Meme generator in c 1

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top