1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

File Operation Question

Discussion in 'C' started by aleefazmir, Sep 3, 2014.

  1. aleefazmir

    aleefazmir New Member

    Joined:
    Sep 3, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I have this one hard questions that I can't find the answer. Anyone of you know how to do this?


    Question 2 (30 marks)


    a) Create a new text file and name it as TEXT1.txt. Write the following content into this text file: Always attend your lecture and tutorial classes Using the C programming language

    i. Create a function named vowelwords(). This function reads the content of TEXT1.txt file and prints out on screen the words that do not start with either an uppercase or lowercase vowel (i.e, with ‘a’,’e’,’i’,’o’,’u’). For example, if TEXT1.txt file contains: Ooi Chee Pun! Always attend your lecture and tutorial classes then Chee Pun! your lecture tutorial classes will be printed on screen. Note: You should determine the appropriate arrays and variables to be used.

    ii. Write a main() function, which calls the created vowelwords() function.


    b) Modify the vowelwords()function in part (a) to write the words that do not start with either an uppercase or lowercase vowel into a new text file called TEXT2.txt.
     
  2. Safari

    Safari New Member

    Joined:
    Oct 16, 2007
    Messages:
    183
    Likes Received:
    17
    Trophy Points:
    0
    Its your homework that you should be doing. We are not your homework doers.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Looks easy enough. 30 marks? No wonder people think exams are getting easier. Anyway, do you understand the question? Where are you stuck? What have you tried?

    You'll probably need a function to read words from the input file. If you haven't got one, you can read one character at a time with fgetc(). For myself I would probably create a state machine that reads one character at a time into a buffer, checking for end of word and changing state accordingly, then on the state transition from word to not-a-word I would call a function which inspects the word that's been read in to determine whether or not it should be printed, then either print it or not depending on the result.

    (b) is then a simple case of modifying the above function, probably by adding an else clause, and I'd probably use fputs() to write the word to the file, or maybe fprintf() so I could easily add formatting (like a space, newlines, etc).
     
    shabbir likes this.

Share This Page