Reputation: 171
Story : HTML-form uses "post
" method to send data. There is only <textarea>
inside the HTML-form
and it requires me to give it a name. I gave it the name "a
". However because of this, the stdin
starts with a=
. In other words it contains 2 characters in the beginning of it that is not needed.
Mission : If possible, read the stdin
starting from the 3rd
character.
Total characters in stdin
: ( prints : 23
)
char* len;
len = getenv("CONTENT_LENGTH");
fputs(len, stdout);
Reading stdin
: ( +1
for the closure
)
char receive[24];
fgets(receive, 24, stdin);
Desired code : ( -2
for a=
)
char receive[22];
// If possible, read stdin starting from the 3rd character,
// until the 24th character.
Upvotes: 2
Views: 282
Reputation: 14491
You can skip 2 characters either by:
getchar() ; getchar() ;
Not flexible, but will do the job.
However, from problem description, looks like you want to split input line into key value pairs, with '=' between key and value. Consider:
char key[20], value[100] ;
if ( scanf("%19[^=]=%99[^\n]", key, value) == 2 ) {
// do something with key, value
} ;
Upvotes: 3