1

I've already solved this by not displaying the last letter of the word then locating the last letter and making it blink then I displayed the word inversely minus the last letter of course.

  #include<string.h>    
  #include<conio.h>
  #include<iostream.h>
  #include<stdio.h>

char text[255];
int txtposition,txtlength;

void main()
{
clrscr();
gets(text);
txtlength=strlen(text);

char lastchar=text[txtlength-1];
cout<<"Your text is: ";
for(txtposition=0;txtposition<txtlength-1;txtposition++)
{
cout<<text[txtposition];
}
textcolor(WHITE+128);
cprintf("%c", lastchar);


for(txtposition=txtlength-2;txtposition>=0;txtposition--)
{
  cout<<text[txtposition];
}

getch();
}

Thank you for all your help!

Jane Doe
  • 29
  • 7
  • 1
    `iostream.h` isn't and never was a thing in C++, `string.h` and `stdio.h` are deprecated and TurboC++ is horribly outdated. If you want to do more with C++ than passing this class, you should invest in some good learning material and get an up-to-date compiler. – Baum mit Augen Apr 11 '16 at 16:13
  • i see, what do you suggest? – Jane Doe Apr 11 '16 at 16:14
  • [Here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) are popular C++ books (although I don't know most of them myself). Common compilers these days are gcc, clang (both free and open source) or MSVC++ (free for non-commercial use afaik). – Baum mit Augen Apr 11 '16 at 16:16
  • @BaummitAugen: Yes, "iostream.h" was a thing in C++, prior to iso standardization. – Benjamin Lindley Apr 11 '16 at 16:17
  • 1
    Join the 21st century and get a [modern free compiler](http://www.stroustrup.com/compilers.html). – NathanOliver Apr 11 '16 at 16:17
  • @BenjaminLindley Fair enough, should have written "in standard C++" instead. Still, not a thing in almost two decades. – Baum mit Augen Apr 11 '16 at 16:18
  • @JaneDoe: `void main` is non-standard and more to write than standard `int main`. Where did you pick that up? – Cheers and hth. - Alf Apr 11 '16 at 16:31
  • @Cheersandhth.-Alf Ancient Indian textbook I would guess. – Baum mit Augen Apr 11 '16 at 16:40
  • @JaneDoe [This](https://stackoverflow.com/questions/31274000/how-to-blink-particular-text-continuously-all-time-during-input-and-output) might help. – Baum mit Augen Apr 11 '16 at 16:40

3 Answers3

0

To make the middle character blink, either your output terminal needs to be capable to present blinking characters using a special terminal control code as described here, or use the gotoxy() function from a separate thread, that displays a ' ' or the actual character, alternating for a specific blink frequency.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
0

The standard C++ library does not provide any facility for making characters blink.

You can do that in platform-specific ways, but it's worth noting that Windows console windows do not (as far as I know) directly support text blinking, like the original IBM PC's text screen mode did. On the original IBM PC one bit of the color specification could be configured to either yield high intensity or blinking, with blinking control as the default. I always reconfigured it to high intensity in my programs, and in the corresponding mechanism for Windows console windows the bits always determine color.

So, it would be complicated to do even in Windows, unless you're running in a DOSBox, which emulates the old PC. I don't know what functionality it offers. Maybe it even does blinking.

But you can easily mark the relevant letters in other ways.

For example, you could use

  • uppercase versus lowercase,

  • underlining characters placed on the next line,

  • parentheses (as you did in your example here),

  • colors (platform specific),

  • a different font, boldness, whatever.

I recommend updating to a modern compiler, if you have an ordinary modern PC. Compilers are free. Also you need better learning material, e.g. void main is non-standard and is only accepted by a few compilers.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • @JaneDoe: **if** DOSBox supports it, then you should be able to use Turbo C++'s `textattr` function. Embarcado still provides [documentation](http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devwin32/textattr_xml.html). However, I think "bit 8" in that documentation is wrong: as I recall the color spec is one single byte, and it's bit 7 that is configurable and controls blinking by default. So you would add 2^7 = 128 to get a "color" that blinks. – Cheers and hth. - Alf Apr 11 '16 at 16:51
  • i see but my question is how do i get the middle letter? – Jane Doe Apr 11 '16 at 16:54
  • @JaneDoe: For this technique you would output everything up to the middle letter, call `textattr` as appropriate to turn blinking on, output the middle letter, call `textattr` to turn blinking off, and output the rest. :) – Cheers and hth. - Alf Apr 11 '16 at 16:56
  • i see but still it kinda confuses me. – Jane Doe Apr 12 '16 at 11:40
  • how do i output the middle letter? – Jane Doe Apr 12 '16 at 11:48
  • The same way as the rest, I presume. – Cheers and hth. - Alf Apr 12 '16 at 14:52
  • i'm still confused :( sorry im so dumb – Jane Doe Apr 12 '16 at 16:25
  • @JaneDoe: Uhm. Currently the code first outputs the complete original text, `cout << text;`, and then it uses a `for` loop to output in reverse the characters except the last one (which is the middle character in the output). So, building on what you have, just doing more of the same, you can replace the `cout << text` with a `for` loop that outputs all the characters except the last one (which will become the middle character in the output). Then apply blinking. Then output that character. Then turn off blinking. Then the last `for` loop just as it already is. Did that make sense? – Cheers and hth. - Alf Apr 12 '16 at 17:20
  • and hth- alf: I understand now. i've come up with this for loop but the problem it displays all the characters how can i modify it so it will exclude the last one? for(txtposition=0;txtposition<=txtlength;txtposition++) { cout< – Jane Doe Apr 13 '16 at 03:07
  • @JaneDoe: Well this is a loop that counts up and executes its body *n* times, so ideally all you have to do is reduce by 1 the value that it counts up to, so that it now only executes its body *n*-1 times. However, note that as shown, using `<=` for comparison, it already goes *one time too many*, outputting the zero-byte at the end of the string. So first make it correct, *then* reduce the number that it counts up to. – Cheers and hth. - Alf Apr 13 '16 at 03:10
  • i've got it thanks for all your help :) now, the only problem i got is how to display the middle letter. XD – Jane Doe Apr 13 '16 at 03:40
0

Looks like for Turbo C/C++ you can you use the Graphics library and/or builtin conio functions. ( https://answers.yahoo.com/question/index?qid=20080813072809AAEguz0 )

But the above is not portable as the graphics library is specific to Turbo and conio is specific to some dos based compilers/libraries.

If you move to the a complier like gcc/g++ then you might want to look at curses library: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

Carlos
  • 358
  • 2
  • 10