Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Need help in C program (http://www.go4expert.com/forums/help-c-program-t23999/)

cbeginnerstudent 26Nov2010 15:14

Need help in C program

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.


virxen 27Nov2010 05:04

Re: Need help in C program
start coding and we will help you.

xpi0t0s 29Nov2010 13:44

Re: Need help in C program
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.

All times are GMT +5.5. The time now is 17:29.