故事:HTML 表单使用“post
”方法发送数据。只有<textarea>
里面HTML-form
它需要我给它起一个名字。我给它起了个名字“a
”。然而正因为如此,stdin
以 a=
开头。换句话说,它的开头包含 2 个不需要的字符。
使命:如果可能,请阅读 stdin
从3rd
开始性格。
stdin
中的总字符数: ( 打印 : 23
)
char* len;
len = getenv("CONTENT_LENGTH");
fputs(len, stdout);
阅读stdin
: ( +1
为 closure
)
char receive[24];
fgets(receive, 24, stdin);
所需代码:( -2
为 a=
)
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/