Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help! (http://www.go4expert.com/forums/help-t27712/)

maustelistu 2Feb2012 15:40

Help!
 
Can someone help me?

There is a text file. Make a C application in which you type a string, which counts the number of times the string is contained in the text file and print it on the display. Make a new text file which has the initial text file content but in which it is eliminated the string typed at the beggining.

Sorry for my english, I'm not quite good at it.

xpi0t0s 3Feb2012 05:11

Re: Help!
 
How far have you got and where are you stuck?
Do you understand the requirements?
What algorithm do you think you might use (as in: how do you think the program will work)?

maustelistu 3Feb2012 06:27

Re: Help!
 
Well... I'm stuck at ... Making the function to search the string inside the file and printing into another file the whole text eliminating the string

xpi0t0s 3Feb2012 13:12

Re: Help!
 
OK. I get the feeling you want me to write it for you. That's not going to happen, so if that's what you want, this conversation ends here. I'll help you write it, but that's all. It's not up to me to do your homework for you.

Let's start with something simple. Do you know how to create a function that will search inside a file for a string? This will involve opening a file and reading characters from it. Get that working, then move onto the next step.

Maybe I'm jumping to the wrong conclusion. A very common beginner mistake is to try to write the whole program at one go, much like you would write an essay, and simply be overawed by it. For some reason teachers don't tend to teach an incremental approach. Let me let you into a secret: most code is written incrementally: that is, we start with a "hello world" program, then add a small amount of functionality to it and make sure that works, befor adding another bit of functionality, and so on until the program is complete. So in this case your first bit of functionality might be to open the file, read the characters in it and display them to screen, or send them to another file. Having created the stream, you then add the code to locate the desired string within the stream, and maybe print something like "Got it!" on the screen. Then debug the string finding code. Finally modify the program to remove that string from the stream and it's done.

Scripting 3Feb2012 13:22

Re: Help!
 
Quote:

Originally Posted by xpi0t0s (Post 91912)
OK. I get the feeling you want me to write it for you. That's not going to happen, so if that's what you want, this conversation ends here. I'll help you write it, but that's all. It's not up to me to do your homework for you.

Let's start with something simple. Do you know how to create a function that will search inside a file for a string? This will involve opening a file and reading characters from it. Get that working, then move onto the next step.

Maybe I'm jumping to the wrong conclusion. A very common beginner mistake is to try to write the whole program at one go, much like you would write an essay, and simply be overawed by it. For some reason teachers don't tend to teach an incremental approach. Let me let you into a secret: most code is written incrementally: that is, we start with a "hello world" program, then add a small amount of functionality to it and make sure that works, befor adding another bit of functionality, and so on until the program is complete. So in this case your first bit of functionality might be to open the file, read the characters in it and display them to screen, or send them to another file. Having created the stream, you then add the code to locate the desired string within the stream, and maybe print something like "Got it!" on the screen. Then debug the string finding code. Finally modify the program to remove that string from the stream and it's done.

Nicely said. :D


All times are GMT +5.5. The time now is 03:16.