We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
because of the space that you put between %lld and %c , your first scanf expects that you will type a space and scanf will "absorb" it and forget about it immediately,without putting it as value into any variable. Try a program of reading times with following code
{ int hours,min,secs;
scanf("%d:%d:%d");
printf("Hours %d , minutes %d and seconds %d \n",hours,min,secs); return 0; }
and type as user things like 4:35:56 , and see the result!You will see that the ':' characters that you typed were thrown in "nonexistence" , because scanf was expecting them to come. So only the integers were read. The same thing happens to space character.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Basic Data Types
You are viewing a single comment's thread. Return to all comments →
because of the space that you put between %lld and %c , your first scanf expects that you will type a space and scanf will "absorb" it and forget about it immediately,without putting it as value into any variable. Try a program of reading times with following code { int hours,min,secs; scanf("%d:%d:%d");
printf("Hours %d , minutes %d and seconds %d \n",hours,min,secs); return 0; } and type as user things like 4:35:56 , and see the result!You will see that the ':' characters that you typed were thrown in "nonexistence" , because scanf was expecting them to come. So only the integers were read. The same thing happens to space character.