<html><body>Bohužel, takhle hezky funguje getchar jen na jednočipech.<div>Tady mi, stejně jako na win čeká ještě na enter.<div><br></div><div>PH</div><div><br><aside>
---------- Původní e-mail ----------<br>
Od: iko <iko.ikoon@gmail.com><br></aside><blockquote data-email="iko.ikoon@gmail.com">#include <stdio.h><br>int main (int argc, char **argv){<br>   char c = getchar();<br>   printf("Char: %c", c);<br>   return 0;<br>}<br><br>On 9/3/21 11:54 AM, Pavel Hudeček wrote:<br>> Potřebuji něco, co by v linuxové konzolové aplikaci čekalo na stisk <br>> klávesy a pak detekovalo jaká to byla. Tzn něco ve stylu:<br>> Press Y to Yes or N to No<br>> Chci ale, aby *nebylo potřeba mačkat enter*.<br>> <br>> Ve windows používám:<br>> // wait for user choice from 2 to 3 keys (key3=0 or key4=0 -> not used)<br>> // key1/key2/key3 is lower case, keyboard input is independent ===================================<br>> char choiceKey(char key1, char * text1, char key2, char * text2, <br>> char key3=0, char * text3="", char key4=0, char * text4="") {<br>> char ch;<br>> <br>> while(1) {<br>> *ch = _getch()*;<br>> if (ch<'a' && ch>='A' && ch<='Z') ch += 'z'-'Z'; // convert to lower case<br>> if (ch==key1) {<br>> if (text1[0]!=0) printf("%s\n", text1);<br>> break;<br>>          } else if (ch==key2) {<br>> if (text2[0]!=0) printf("%s\n", text2);<br>> break;<br>>          } else if (key3!=0) if (ch==key3) {<br>> if (text3[0]!=0) printf("%s\n", text3);<br>> break;<br>>          } else if (key4!=0) if (ch==key4) {<br>> if (text4[0]!=0) printf("%s\n", text4);<br>> break;<br>>          }<br>>      }<br>> return ch;<br>> }<br>> Jenže _getch není, resp. není conio.h.<br>> Našel jsem:<br>> https://stackoverflow.com/questions/8792317/where-is-the-conio-h-header-file-on-linux-why-cant-i-find-conio-h<br>> Doinstaloval:<br>> sudo apt-get install libncurses5-dev libncursesw5-dev<br>> Použil curses.h a z něj cbreak + getch<br>> Jenže:<br>> /usr/bin/ld: /tmp/cceqblBw.o: undefined reference to symbol <br>> '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'<br>> /usr/bin/ld: //lib/arm-linux-gnueabihf/libstdc++.so.6: error adding <br>> symbols: DSO missing from command line<br>> <br>> A dál už nevím, je to RPI s 32b ARM<br><br></blockquote></div></div></body></html>