echoing input to screen with bgi

I want to enter a name and have it echo to the screen as I input and then save the string to a designated place.


I keep getting the error:
cannot convert parameter 3 from 'char' to 'const char *'

I can get one letter write to screen by:

char name;
name = getch();
outtextxy(40,40,&name);

but I get a bunch of crap after it.

This is probably very simple, but I am a noob to programming.

Thanks,

Matt




Comments

  • : I want to enter a name and have it echo to the screen as I input and then save the string to a designated place.
    :
    :
    : I keep getting the error:
    : cannot convert parameter 3 from 'char' to 'const char *'
    :
    : I can get one letter write to screen by:
    :
    : char name;
    : name = getch();
    : outtextxy(40,40,&name);
    :
    : but I get a bunch of crap after it.
    :
    : This is probably very simple, but I am a noob to programming.
    :
    : Thanks,
    :
    : Matt
    :
    :


    You shouldn't get that warning. Anyway, the code has a bug. outtextxy() expects a null-terminated string. By just passing a single char, outtextxy() won't find the null-termination and will therefore read junk from the memory until it finds a cell containing the value 0.

    Do like this instead:

    [code]
    char name[2];
    name[0] = getch();
    name[1] = '';
    outtextxy(40,40,name);
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion