Hi! I want to execute a method without pressing the enter key, what I want to do is get the press key an save it in an array while the user is typing, but I dont know how to execute an event without pressing the enter key

here is my code:

void productor(){
    char tecla=getchar();
    while (contador<50){ 
        buffer[contador]=tecla;
        contador++;
        }
    }   

Standard C++ does not allow this. Only a couple compilers have extensions that will, but learning to rely on non-standard functionality hurts you when you need to use different compilers.

Won't getch() do the trick?
something like his while loop
with getch as the first command everytime?

or am i missing something?

char charArray[50]
int k=0
while(k<50)
---charArray[k]=getch()
---k++

why do you want to do this?

Won't getch() do the trick?

It's not part of the standard library. Microsoft includes getch() it in the conio.h header, but I'm not sure what's used (if anything) with other compilers/operating systems.

Are my eyes tricking me? where did he say he doesnt want to use the non standard libraries?
he even used it in his code just in the wrong place :O
though i could be wrong >.<

where did he say he doesnt want to use the non standard libraries?

He didn't.

We prefer to suggest standard functionality rather than relying on tricks and non-standard techniques because you cannot transfer the non-standard skills to other compilers. Especially things like getch().

Also, if he's using g++, Watcom, or any of a couple hundred other compilers, using getch() isn't even an option. So we keep our help standard unless specifically asked.

he even used it in his code just in the wrong place :O
though i could be wrong >.<

Yes, you are wrong. His code is standard.

oh my bad, guess i have to lower the resolution >.<
so anyway no option to get stream from the keyboard?
how sad :O!

so anyway no option to get stream from the keyboard?

No portable option. There are non-portable options, but we kind of have to know what OS and compiler are being targeted before any viable options can be suggested.

yes, I am using gcc compiler and I want to use standar libraries for the solution, that I am seeing it's no possible to do it, but thanks anyways!

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.