Я думаю, что вы имеете в виду следующее, если пробел, за которым следует клавиша ввода, допустим, учитывая ваши комментарии выше.
char input = 0;
while( input != ' ' )
{
printf("Press space bar to continue...\n");
scanf("%c",&input);
}
Или, если хотите, без нажатия клавиши ввода:
#include <stdio.h>
int main(int argc, char **argv)
{
char input = 0;
while( input != ' ' )
{
printf("Press space bar to continue...\n");
input = getch();
}
}
Это работало на моей оболочке msysgit bash. НО, некоторые люди будут настаивать на том, что она работает и на Linux. Это нормально, я думаю, я люблю Linux, но я сказал, что вышеупомянутое решение работает на msysgit . Следующее работает на моем, позвольте мне быть конкретным, Oracle VM для Ubuntu 10.10.
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int main(int argc, char **argv)
{
char input = 0;
while( input != ' ' )
{
printf("Press space bar to continue...\n");
input = mygetch();
}
}
int mygetch(void)
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
mygetch
пришел от сюда .