Sorry it is not a pure c question but please explain me. I am confused with state diagram and flow chart. Should i do C program based on flow chart or state diagram. I am finding state diagram easy to implement. Please help.
Sorry it is not a pure c question but please explain me. I am confused with state diagram and flow chart. Should i do C program based on flow chart or state diagram. I am finding state diagram easy to implement. Please help.
Use whatever seems appropriate to help you plan your logic. For instance, I occasionally use flow charts when I have to institute a complex set of dependent conditions, since it helps me visualize all the necessary logical branches. More often, pseudocode is sufficient to determine the logic, with the added benefit of easy pseudocode-to-code translation.
Thank you for the reply. Does pseudo code development involves some tools and will they automatically generate C code. I am finding it very difficult to maintain C code and also development is taking lot of time. In some or the condition i am failing to update a flag and etc. How to reduce these kind of mistakes? Any suggestions.
I just use a simple text editor for most of my pseudocode development. It is your responsibility to convert it to code.
For more sophisticated programs, I spend much more time on planning and pseudocode than actual coding. You can read through the pseudocode to ensure the logic makes sense and is correct. It also helps identify values you will need, repeated actions that can be partitioned into separate functions, etc. It can also serve as informal documentation on the logic (as long as you keep it updated if things change during coding).
The more detailed your pseudocode, the easier it is to translate into actual code. If updating a flag is important to a given algorithm, the pseudocode should show this - omitting it is a logical mistake that should found during a review (well before any actual coding has taken place).
If you're a beginner, and have sufficiently detailed pseudocode, a good technique is to copy/paste the pseudocode into your source file, comment each line, and below each line write the corresponding code. When you're done, deleted the commented lines (as such verbose comments in the final code are not needed). Since you already know the logic is sound (since it should have been verified earlier), you have a much better chance of writing correct code the first time around.
Proper design does take a lot of time, but helps reduce time coding, since you (1) don't have to figure things out as you go, and (2) don't have to do major code re-writes because certain things had not been taken into account. The more time you spend planning, the better your logic will be and the easier it will be to write efficient code.