I have been using C for a while, but I encountered this today and its behavior is different from what I expected.
scanf("%d,%d",&d1,&d2);
this matches "1,2" as expected but it also matches "1, 2", why?
Since it matches "1, 2" I thought maybe its because scanf ignores whitespace before any non whitespace character, but it does not match "1 , 2". So scanf ignores the whitespace before 2 but not the whitespace before ,? Why is this happening?
scanf("%d,%d",&d1,&d2);
this matches "1,2" as expected but it also matches "1, 2", why?
Since it matches "1, 2" I thought maybe its because scanf ignores whitespace before any non whitespace character, but it does not match "1 , 2". So scanf ignores the whitespace before 2 but not the whitespace before ,? Why is this happening?
Last edited: