c - Scanf with a specific format -


i allow user put input in specific format.
the format:
a=1,b=-2,c=3 example. spaces allowed inbetween commas , characters.
i'm using: if (scanf("a=%lf,b=%lf,c=%lf",&a,&b,&c) == 1) reason doesn't work. how can fix it?

you converting 3 numbers, return value should 3 if conversions successful. note %lf ignores spaces before number. if want ignore spaces around , , before = or a, add space in format string:

double a, b, c;  if (scanf(" =%lf , b =%lf , c =%lf", &a, &b, &c) == 3) {     /* conversion successful, 3 numbers parsed */     ... } 

note scanf() not ignore space characters, ignore , whitespace characters, including newlines, tabs, etc.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -