Click here to Skip to main content
16,020,103 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
if it separate to four function it is easy but i don't know how to do it one function

What I have tried:

i tried to search online and i still can't fix it so can u have me
Posted
Updated 4-Dec-17 20:37pm
v2

1 solution

If you can do it in four functions, then do it in four functions! That way, it's a lot more readable, and a whole load more maintainable.

Collapsing functions into one isn't often a good idea - there is a design philosophy called "separation of concerns" which says that a function should have one job and tat separate jobs are done by separate functions.

But if you must, then just take the code out of one function and transplant it into your calling function. Get that working, then repeat for the others, one at a time.
 
Share this answer
 
Comments
victor hsu 1B 5-Dec-17 2:43am    
this is our homework and i have to do, and like first function is read file and second is sort, third is compare string, fourth is swap string, and our teacher want us to put four function in one code and run.
OriginalGriff 5-Dec-17 2:57am    
All the more reason why you need to do it yourself - you won't learn anything by copying and pasting a solution.
So look at what I said, and try transplanting the first function's code.

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