Need help in C program

cbeginnerstudent's Avatar, Join Date: Nov 2010
Newbie Member
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
virxen's Avatar, Join Date: Nov 2009
Pro contributor
start coding and we will help you.
xpi0t0s's Avatar, Join Date: Aug 2004
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.