2

我正在尝试使用fscanf()读取必须前后有空格的字符:

fscanf( input, "%*[ \t]%c%*[ \t]", output )

但不幸的是,"%*[ \t]"格式说明符接受零个或多个匹配项。无论如何我可以要求它接受至少一场比赛,还是我需要使用类似的东西getc()

4

1 回答 1

1

有可能解决这篇文章,fscanf()但让我们看看一种fgetc()方法。

// return 1 on success, else return 0
int GetSpaceCharSpace(FILE *istream, int *ch) {
  *ch = fgetc(istream);
  if (!isspace(*ch))
    return 0;

  // consume additional leading spaces as OP said "accept at least one match"
  while (isspace(*ch = fgetc(istream)))
    ;
  // Code has a non-white-space

  // Success if next char is a white-space
  return isspace(fgetc(istream));
}
于 2015-03-03T00:19:49.417 回答