1
В моем коде ниже я пытаюсь игнорировать новые строки. Есть ли лучший способ сделать это?Как вы можете получить символы без n?
do
{
scanf("%c",&wouldCount);
} while(wouldCount == '\n');
оригинальный код
#include <stdio.h>
int main()
{
char Yes = 'Y';
char wouldCount;
int counter;
int start;
int end;
int increment;
const END_DEFAULT = 1;
const INCREMENT_DEFAULT = 1;
printf("Would you like to count?");
scanf("%c",&wouldCount);
while(wouldCount == 'Y' || wouldCount == 'y')
{
printf("Please enter start number.");
scanf("%d",&start);
printf("Please enter a number you would like to stop at?");
scanf("%d",&end);
printf("Please enter a number to increment by.");
scanf("%d",&increment);
if(end < start)
{
end = start + END_DEFAULT;
}
if(increment <= 0)
{
increment = INCREMENT_DEFAULT;
}
for(counter = start; counter < end; counter += increment)
{
printf("%d\n",counter);
}
printf("Would you like to count?");
do
{
scanf("%c",&wouldCount);
} while(wouldCount == '\n');
}
return 0;
}
Я не понимаю, что вы имеете в виду. Нужно ли игнорировать новые строки? – Jim
Я не хочу, чтобы он вышел, когда я нажимаю enter, во время запуска программы. – user494243