SetConsoleTextAttribute causes an error (I wanna highlight entered name)

How I fix the code? When I run it and type something for name, I get error and program closes.I Want highlight Entered name with different color.

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
42
43
44
45
46
47
48
49
/* scanf example */
#include <stdio.h>
#include <windows.h>

int main ()
{
const WORD colors[] =
		{
		0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F,
		0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6
		};

	HANDLE hstdin  = GetStdHandle( STD_INPUT_HANDLE  );
	HANDLE hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
	WORD   index   = 0;

	// Remember how things were when we started
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	GetConsoleScreenBufferInfo( hstdout, &csbi );

	// Tell the user how to stop
	SetConsoleTextAttribute( hstdout, 0x07 );


  char str [80];
  int i;

  printf ("What's ur name: ");
  scanf ("%s",str);
  printf ("U got nice name ");
  SetConsoleTextAttribute( hstdout, 0x0A );
  printf ("%s \n");
  SetConsoleTextAttribute( hstdout, 0x07 );

  printf ("but say %s how old are you?");
  scanf ("%d",&i);
 if ( i < 10 or i == 10 ) {
      printf ("U are pretty young\n");
  }
  else if ( i > 10 and i < 100 ) {
    printf ("You are pretty old \n");
  }
  else {
    printf ("Now u lie\n \n");
  }
  printf ("Leave? [Y]");
  scanf ("%e",str);
  return 0;
}
You need to turn your compiler warnings on and fix those errors. Using the GCC I get:
b.c: In function 'main':
a.c:32: warning: too few arguments for format
a.c:35: warning: too few arguments for format
a.c:37: error: expected ')' before 'or'
a.c:40: error: expected ')' before 'and'
a.c:47: warning: format '%e' expects type 'float *', but argument 2 has type 'char *'
a.c:15: warning: unused variable 'index'
a.c:13: warning: unused variable 'hstdin'
a.c:7: warning: unused variable 'colors'

After fixing the errors the program worked fine for me.
Topic archived. No new replies allowed.