Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A string is given
567*892 = water64

How to replace water in output by 5057

What I have tried:

Don't have any idea how to get through this problem. Can anyone help?
Posted
Updated 1-Sep-19 22:02pm
Comments
Thomas Daniels 1-Sep-19 13:16pm    
Is your question just how to replace "water" with "5057" in a string, or how to 'fix' any kind of expression in a format like this?
Richard MacCutchan 1-Sep-19 13:22pm    
You could use a regex or just copy characters into a new string, replacing "water" by "5057". Either way it is a good exercise for you to try.

I'd suggest you go back to your teacher, or the question as set and read it again: the result of 567 * 892 is 505764, so I can see why the 64 part exists in your solution - but unless the question specifically wants you to locate the string "water" and always replace it with the remains of the calculation "5057" as a constant string I think you have rather missed the point. It's unlikely that a constant "replacement" is what is wanted, particularly since the string you are replacing isn't the same size as the string you are replacing it with - and in C that takes some thinking about if you aren't going to cause memory problems.

I'd double check the question really carefully before you go any further.
 
Share this answer
 
I'd rather not write down the program for you, since you need to learn finding the solution for yourself. And that is more important than knowing the solution.

Instead, I suggest you look up the C string functions, e. g. at C - Strings and String functions with examples[^].

You'll find plenty of information on C strings in general, and explanations with examples for each C string function. Probably there is at least one useful example program that you could use as a starting point to solve your task.
 
Share this answer
 

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