Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to do this question?I don't know the answer please help me out.

What I have tried:

i don't know the answer let me know.how to do this question?I don't know the answer please help me out.
Posted
Updated 28-Sep-17 20:09pm
Comments
CPallini 29-Sep-17 3:12am    
Write the code, debug it and enjoy.
Richard MacCutchan 29-Sep-17 5:24am    
Have a guess.

1 solution

Chances are that the question is not that: the file content is more likely to be "I love computer\r\n" which is very different.

But this is your homework: so it's your task.
Start by looking at the definition of fgets: fgets - C++ Reference[^] and it's obvious that what you get will depend on the parameters you pass to it - the count is significant. If the count is 3, you will get four characters stored in the buffer: 'I', ' ', 'l', and '\0' - the last being a null terminator to mark the end of the string. Other values will give you other results...

Try it: look at the question, set up the file, and write the code to do it, and use the debugger to find out exactly what happens. This isn't complicated!
 
Share this answer
 
Comments
CPallini 29-Sep-17 3:11am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900