Не могу ввести строку как пользователь - C (СИ)
Формулировка задачи:
Здравствуйте.
Подскажите, плз, в чем ошибка, в строках 27-28 вводится запрос на ввод строки, однако возможности ввести не предоставляется и программа идет дальше.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
char N[100];
int chet,N_c;
printf("Enter integer N\n");
scanf ("%s",&N);
N_c=atoi(N);
chet=0;
while (N[chet]>='0' && N[chet]<='9')
chet++;
if ((N[chet]=='\0') && (N_c>0)) //Если N целое и положительное число
{
char file_names[254];
puts("\nEnter the file names separated by commas and click Enter");
gets(file_names);
int chet_ch_failov=0;
int i_c=0;
while (file_names[i_c]!='\0')
{
if(ispunct(file_names[i_c]))
chet_ch_failov++;
i_c++;
};
chet_ch_failov++;
if (chet_ch_failov>N_c)
{
printf("Vse kruto\n");
}
else
{
printf("N exceeds the number of files. Try again, please.\n");
}
}
else
{
printf ("You entered a negative, or float N, or null. Try again, please.\n");
}
getch();
}Решение задачи: «Не могу ввести строку как пользователь»
textual
Листинг программы
char file_names[254];
puts("\nEnter the file names separated by commas and click Enter");
fflush(stdin);
gets(file_names);
Объяснение кода листинга программы
- Объявляется массив
file_namesтипаcharс размером 254 символа - Выводится сообщение с просьбой ввести имена файлов, разделенные запятыми, и нажать Enter
- Используется функция
fflush(stdin)для очистки буфера ввода - Вводится строка с помощью функции
gets(file_names)