c99 - Any way to to include original parameters in fscanf in C -
i'm trying see if when do
fscanf(inputstream, "$%s$", out) i can return $ signs - there way?
i don't think there's way retrieve string dollar signs , non-blank string between them using scanf() family of functions. closest approach using scanset, scansets not same regular expressions, , you'd need regular expression specify pattern looking for.
in practice, first dollar sign string using:
fscanf(inputstream, " %1[$]%[^$]%*[$]", &out[0], &out[1]); you can't pull same stunt latter dollar sign, if know exact length of string. trouble you'd need overwrite null @ end of string second dollar sign, , you'd want nul '\0' after string. adding final dollar easier inserting first @ beginning of string. third scanset contains assignment-suppressing '*' , requires dollar @ end. leading space in format skips spaces.
this isn't guaranteed behaviour; first conversion write nul on out[1], , second conversion write string on out[1], c standard not guarantee work.
#include <stdio.h> int main(void) { char out[20]; scanf(" %1[$]%[^$]%*[$]", &out[0], &out[1]); printf("<<%s>>\n", out); return 0; }
Comments
Post a Comment