1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Need help in C program

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

  1. cbeginnerstudent

    cbeginnerstudent New Member


    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.

  2. virxen

    virxen New Member

    start coding and we will help you.
  3. xpi0t0s

    xpi0t0s Mentor

    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