Need help in C program

Discussion in 'C' started by cbeginnerstudent, Nov 26, 2010.

  1. cbeginnerstudent

    cbeginnerstudent New Member

    Joined:
    Nov 26, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I am new to C language. Please help me to write the code to solve the below question.
    Thanks in advance.

    Q.Write a program for the following

    1. A file name is command line argument. Display the contents of the file where each word will be displayed on a new line. Display proper message if file does not exist.

    2. Display no. of vowels stored in the file.

    3. Display no. of ìtheî stored in the file.

    4. Copy contents of the file to another file.


    Regards,
    Cbeginner
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    start coding and we will help you.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    We can help you but we aren't going to do it for you. Where are you stuck? None of it looks difficult.

    1. OK, so you need to look at argc and argv. Have you covered that in class?

    2. So you need to get characters from the file. Have you covered that? fgetc perhaps? Have you covered opening a file in read-only mode and closing it at the end, and looping over the file getting characters from it?

    3. Display number of vowels. OK, so you need to store the number somewhere, that means you need a variable initialised to zero. Each time fgetc returns a vowel, increment that variable, and after you've hit EOF on the input file, display that variable along with some meaningful text.

    4. I've no idea what an ithei is. But you can solve this in the same way as 3, just have a variable that is incremented each time fgetc gives you an ithei.

    5. You need to get a filename from somewhere (would that also be in argv?), open that file in write mode (which you should have covered by now) then use fputc on each character. Don't forget to close the file when you've finished with it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice