c - fgets + 标准输入 : Is it possible to skip first 2 characters?

标签 c

故事:HTML 表单使用“post”方法发送数据。只有<textarea>里面HTML-form它需要我给它起一个名字。我给它起了个名字“a”。然而正因为如此,stdina= 开头。换句话说,它的开头包含 2 个不需要的字符。

使命:如果可能,请阅读 stdin3rd开始性格。

stdin 中的总字符数: ( 打印 : 23 )

char* len;
len = getenv("CONTENT_LENGTH");
fputs(len, stdout);

阅读stdin : ( +1closure )

char receive[24]; 
fgets(receive, 24, stdin);

所需代码:( -2a= )

char receive[22];
// If possible, read stdin starting from the 3rd character, 
// until the 24th character.

最佳答案

您可以通过以下方式跳过 2 个字符:

getchar() ; getchar() ;

不灵活,但可以完成工作。

但是,从问题描述来看,您似乎想将输入行拆分为键值对,键和值之间使用“=”。考虑:

   char key[20], value[100] ;
   if ( scanf("%19[^=]=%99[^\n]", key, value) == 2 ) {
       // do something with key, value
   } ;

关于c - fgets + 标准输入 : Is it possible to skip first 2 characters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58245809/

相关文章:

c - 从 char 响应缓冲区中提取 JSON 文本

c - 为什么这里没有生成 Coredump 文件?

c - 数组名是指针吗?

c - 如何逐位打印一个数字?

C中#include的成本

C 如何从主范围获取 "hide"宏

c - 使用 SDL_strdup 和类似工具获取文件名时出现问题

c - 使用 Debug模式构建 binutils

c - 循环内的堆栈分配

c - 无法将 '#' 字符作为命令行参数传递