some problems of C scripts in Unix

Discussion in 'C Programming' started by kamkwokho, Jul 6, 2003.

  1. kamkwokho

    kamkwokho Guest

    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.
     
    kamkwokho, Jul 6, 2003
    #1
    1. Advertising

  2. "kamkwokho" <> wrote in message
    news:be9e8c$65j$...
    > 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
     
    Jason Bennett, Jul 6, 2003
    #2
    1. Advertising

  3. kamkwokho

    Malcolm Guest

    "kamkwokho" <> 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.
     
    Malcolm, Jul 6, 2003
    #3
  4. kamkwokho

    Ed Morton Guest

    "Malcolm" <> wrote in message
    news:be9k2q$m57$...
    >
    > "kamkwokho" <> 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.
     
    Ed Morton, Jul 6, 2003
    #4
  5. 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 --
     
    John Tsiombikas (Nuclear / the Lab), Jul 6, 2003
    #5
  6. Richard Heathfield, Jul 6, 2003
    #6
  7. On Sun, 6 Jul 2003 17:55:45 +0100, in comp.lang.c , "Malcolm"
    <> 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 =---
     
    Mark McIntyre, Jul 7, 2003
    #7
  8. kamkwokho

    Daniel Haude Guest

    On Sun, 6 Jul 2003 23:21:20 +0800,
    kamkwokho <> wrote
    in Msg. <be9e8c$65j$>

    > Could any answer following questions as many as you can.


    Yup.

    --
    "With me is nothing wrong! And with you?" (from r.a.m.p)
     
    Daniel Haude, Jul 7, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronnie Laurikkala
    Replies:
    1
    Views:
    572
    Jürgen Exner
    Dec 18, 2003
  2. Jan Danielsson
    Replies:
    8
    Views:
    633
    Mike Meyer
    Jul 22, 2005
  3. Jp Calderone
    Replies:
    0
    Views:
    462
    Jp Calderone
    Jul 21, 2005
  4. davidj411
    Replies:
    0
    Views:
    520
    davidj411
    Jun 27, 2008
  5. Replies:
    13
    Views:
    537
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page