Does anyone know how to put a whitespace or a newline in a .txt file???

By this I mean, I have this long string, and I have to put whitespaces and new lines to make it understandable.

To summarize, I just want to know what functions will be effective to do this

Need an example. you want to change "WethePeopleoftheUnitedStates" to this: "We the People of the United States" ? If the text is in a file then you will have to completly rewrite the file. First open the original file for reading, then another file for writing. In a loop read a line, modify it in memory as desired, then write the modified string to the output file.

Problem: how do you know where to add the spaces and new lines ?

Sorry about that, but yes, that is my problem.

If this is schoolwork then your teacher should tell you how to do it. Otherwise, its nearly impossible for a program to check a string and add spaces where necessary to make it understandable to a human reader. You need to get more information from whoever gave you the requirements for the program.

The input is this "mova,badda,b" and I have to turn it into this:

mov a, b
add a, b

The program doesn't have to be flexible, because there is a given string. My problem is as you said how can I know where to put it

that should be fairly simple. First find the comma and back up one character. That is where you insert the space. Add another space immediately after the command, and a line feed one character beyone that. Do it with two string arrays -- the first is the original string and the second is the altered string.

I would write it for you, but I don't want to spoil all your fun :)

Could you explain the two string arrays further, I'm not that good when it comes to arays, but thanks for the help. At least now I have an idea on how to do it.

>>Could you explain the two string arrays further

You can't use the original string array to insert the spaces for a couple reasons

  • the array may not be large enough to hold the additional characters.
  • the array may be a literal and stored in read-only memory, any attempt to change it would probably crash the program.

So to overcome those problems create another string array that is large enough to hold all the characters in the first plus the additional characters you want to add. Making the second array too large is ok, but too small can be a disaster waiting to happen.

This question has already been answered. Start a new discussion instead.