Hello. I have this problem:

I have a let's say [1000] char string and i want to split and print this on the screen on more lines, so that each and every line has MAXIM 43 characters. The string may contain spaces and the words would be printed on the next line if they cant fit on the current line...

I have no idea how to do that. I know how to show the letters from, lets say [100] to the end of the string, with StringName+100, but how can i show the string from 100 to 143?...

Thank you in advance.

Recommended Answers

All 4 Replies

you will need a second char array. copy the first 43 characters to this second char array array then print it. then print the remainder of the original array.

Use counter which will print the chars.

for(i=0; i<totalLengthOfString; i++)
{
   if(i != 0 && i % MAXIM == 0)
   {
      putchar('\n');
   }
   putchar(string[i]);
}

The second question also can solve with counter.

Use counter which will print the chars.

The second question also can solve with counter.

Yes, that is a better solution than mine -- doesn't require a second buffer.

Thank you very much, the idea is EXCELLENT.

(I had to include ostream for it to work. :p)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.