Вопрос по c, input, string – Как ограничить функцию scanf в C, чтобы печатать ошибки, когда ввод слишком длинный?

3

Error: User Rate Limit Exceededchar* array <String...>Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededscanf("%30s"..)Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Jerry Coffin

Ваш Ответ

6   ответов
1

Error: User Rate Limit Exceeded

#include <string.h>

...

if(strlen(array_ptr) > 0) error();

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
3

Error: User Rate Limit ExceededfgetsError: User Rate Limit ExceededsscanfError: User Rate Limit ExceededfgetsError: User Rate Limit Exceeded30Error: User Rate Limit Exceeded30Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededscanfError: User Rate Limit Exceeded30Error: User Rate Limit Exceeded%32s.

Error: User Rate Limit Exceeded user1386966
2

Error: User Rate Limit Exceeded

  int iCharCount = 0;

  ch = getchar();
  while( ch != EOF ) {
      iCharCount++;
      if(30 < iCharCount)
      {
        printf("You have attempted to enter more than 30 characters.\n");
        printf("Aborting.");
        break;
      }
      printf( "%c", ch );
      ch = getchar();
   }

Error: User Rate Limit Exceeded

3

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded%nError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded%nError: User Rate Limit Exceeded

        ret = sscanf(line, "%d %d %s %d %d %n", &iLoad, &iScreen, &filename, &stage, &bitmapType, &offset);

Error: User Rate Limit Exceededoffset.

0

sscanfError: User Rate Limit ExceededscanfError: User Rate Limit Exceeded\0Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

6

Error: User Rate Limit ExceededscanfError: User Rate Limit Exceeded"%31s"Error: User Rate Limit ExceededstrlenError: User Rate Limit Exceeded

Error: User Rate Limit ExceededstrlenError: User Rate Limit Exceeded%nError: User Rate Limit Exceeded"%31s%n".

Error: User Rate Limit Exceeded%[^\n]Error: User Rate Limit Exceeded%sError: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded%31[^\n].
Error: User Rate Limit Exceeded

Похожие вопросы