sadasdsadsa

hgafghfagfadgeff
Last edited on
The output would be Raceca(R)acecar the middle r blinks


I'd make a copy, replace the (R) with a space in copy, and then alter between printing the original and copy.
Hope it helps.
what do you mean? could you elaborate further?
could you elaborate further?

It's all there.
make a copy.

replace your middle letter with ' '

use if(counter%2 == 0) to print one version and else to print the other. do that 100 times and break out of the loop, it will appear to be blinking. you might have to clear the console too so it appears it's in the same spot.

easy as pie
Turbo C++ version of blinking text:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream.h>
#include <conio.h>
#include <dos.h>

int main()
{
    char text[]  = "Hello World!";
    char text2[] = "      World!";

    for (int i=0; i<10; ++i)
    {
        gotoxy(10,10);
        cout <<  text;
        delay(500);
        gotoxy(10, 10);
        cout << text2;
        delay(500);
    }

    return 0;
}


More up-to-date version for some current Windows compilers:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <Windows.h>
#include <string>

void gotoxy( int column, int line )
{
    COORD coord;
    coord.X = column;
    coord.Y = line;
    SetConsoleCursorPosition(
        GetStdHandle( STD_OUTPUT_HANDLE ),
        coord
    );
}
  
int main()
{
    std::string text  = "Hello World!";
    std::string text2 = "      World!";

    for (int i=0; i<10; ++i)
    {
        gotoxy(10,10);
        std::cout <<  text;
        Sleep(500);
        gotoxy(10, 10);
        std::cout << text2;
        Sleep(500);
    }    
    
}

It's all there.
make a copy.

replace your middle letter with ' '

use if(counter%2 == 0) to print one version and else to print the other. do that 100 times and break out of the loop, it will appear to be blinking. you might have to clear the console too so it appears it's in the same spot.

easy as pie


how would i determine the middle letter of two words? let me rephrase that, how would i determine the last letter of a word. for example, Anna, the output should be Ann[A]nna , a is blinking. i understand what you mean, i just don't know how to do it.
Chervil's solution would be more elegant than mine.

how would i determine the middle letter of two words?

check for NULL and count how many times it isn't

1
2
3
4
5
6
7
8
9
int textLenghtCounter = 0;
for(int i =0; i < 255; i++)
{
  if(text[i])
  textLenghtCounter++; // to get the last letter
  else
  break; 
}
textLenghtCounter /= 2; // to get the middle 




check for NULL and count how many times it isn't

The theory is sound, but no need to reinvent the wheel.
For c-strings there is strlen(), and c++ strings maintain their own size().
http://www.cplusplus.com/reference/cstring/strlen/
http://www.cplusplus.com/reference/string/string/size/
Chervil's solution would be more elegant than mine.

how would i determine the middle letter of two words?

check for NULL and count how many times it isn't

1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
 int textLenghtCounter = 0;
for(int i =0; i < 255; i++)
{
  if(text[i])
  textLenghtCounter++; // to get the last letter
  else
  break; 
}
textLenghtCounter /= 2; // to get the middle  


I've tried this, and it worked for palindromes. However, it doesn't work if the word is not a palindrome like say "potato" it display the letter P instead of o. How can you modify this so it'll still satisfy non-palindrome words? sorry i sound so helpless
@lynlyn9
Here's my version of 'blinking the middle letter', of one word.
The '\b' is backspace's to start the printing at the start of the last print.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<string >    
#include<conio.h>
#include<iostream.>
#include<stdio.h>
#include <Windows.h>

using namespace std;

char text[255];
char text2[255];
int txtposition, txtlength;

int main()
{
	int x;
	cout << "Type a word.." << endl;
	cin >> text;
	cout << "Your text is: " << text << endl << endl;
	txtlength = strlen(text);
	x = txtlength;
	for (txtposition = txtlength - 2; txtposition >= 0; txtposition--)
	{
		text[x] = text[txtposition];
		x++;
	}
	
	for (x = 0; x < strlen(text); x++)
		text2[x] = text[x]; // Make a copy of text[]
	string back(x, '\b'); // Create a variable for backspaces, the length of text[]
	x = (strlen(text)) / 2;
	text2[x] = ' '; // Make center of text2[] a space
	for (;;) // 
	{
		cout << text << back;
		Sleep(350);
		cout << text2 << back;
		Sleep(350);
	}
	_getch();
return 0;
}
@whitenite1

Here's my version of 'blinking the middle letter', of one word.
The '\b' is backspace's to start the printing at the start of the last print.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<string >    
#include<conio.h>
#include<iostream.>
#include<stdio.h>
#include <Windows.h>

using namespace std;

char text[255];
char text2[255];
int txtposition, txtlength;

int main()
{
	int x;
	cout << "Type a word.." << endl;
	cin >> text;
	cout << "Your text is: " << text << endl << endl;
	txtlength = strlen(text);
	x = txtlength;
	for (txtposition = txtlength - 2; txtposition >= 0; txtposition--)
	{
		text[x] = text[txtposition];
		x++;
	}
	
	for (x = 0; x < strlen(text); x++)
		text2[x] = text[x]; // Make a copy of text[]
	string back(x, '\b'); // Create a variable for backspaces, the length of text[]
	x = (strlen(text)) / 2;
	text2[x] = ' '; // Make center of text2[] a space
	for (;;) // 
	{
		cout << text << back;
		Sleep(350);
		cout << text2 << back;
		Sleep(350);
	}
	_getch();
return 0;
} 


thanks a lot for your help, however creating a variable for backspaces gives me an error. It says "Undefined symbol 'string' "
and i also want to point out i cant use windows.h somehow. Did you make this on Turbo C++?
Last edited on
and i also want to point out i cant use windows.h somehow. Did you make this on Turbo C++?

The header <windows.h> is available only on windows systems. If you use another platform, it won't exist. Turbo C++ was originally a DOS program (before windows was even in existence), and a later version was issued for Windows 3.1. Either way, the language it uses is not modern, standard C++.

however creating a variable for backspaces gives me an error. It says "Undefined symbol 'string' "

The code from whitenite1 string back(x, '\b'); uses the standard C++ string, and generates a string containing x occurrences of the character '\b'.

If you are obliged for some reason to use Turbo C++, then you will have to use c-strings (a plain character array, terminated with a null character).
Create an array of sufficient length, fill it with the backspace character '\b' and put a null character '\0' in the array location x+1, to mark the end.

(A better plan is to stop using Turbo C++ as soon as you can - if you need it for an educational course, you may not have much choice, for the time being. But you will later have to unlearn a lot of material in order to use any current C++ compiler).


@chervil thank you for all your help. Hoping to soon use modern C++ compiler.
Topic archived. No new replies allowed.