+ 1
Anyone please tell me the behaviour of this code in C
Especially about scanf() and how it works in this code.... And please help me to understand this second code, which wasn't created by me..... It was created by LastSecond959 https://code.sololearn.com/cD4LRd7155uD/?ref=app https://code.sololearn.com/cqI6avcD27f9/?ref=app
13 Answers
+ 5
In line
scanf("%dss%d",&a,&b);
You are saying to system that first read an integer then 2 's' then another integer.
But store only first and second Integer.
+ 5
Yogeshwaran just convert translate it to english.
if (h==12 && (time=='A' || time=='a')) h=0;
If "h" is equal to 12 AND "time" is either 'A' or 'a' then convert "h" to 0
+ 4
+ 3
It's how scanf work: http://www.cplusplus.com/reference/cstdio/scanf/
Non-whitespace character, except format specifier (%): Any character that is not either a whitespace character (blank, newline or tab) or part of a format specifier (which begin with a % character) causes the function to read the next character from the stream, compare it to this non-whitespace character and if it matches, it is discarded and the function continues with the next character of format. If the character does not match, the function fails, returning and leaving subsequent characters of the stream unread.
+ 3
Yeah as Arsenic said👆
The parenthesis are there because && have an higher precedence than ||, so without them it would be like
if ((h==12 && time=='A') || time=='a')
Which means if h is 12 and time is A, or if time is a
Anyway in the challenge they give AM and PM uppercase, there's no need for the lowercase condition
+ 3
The condition was :
if (h==12 && (time=='A' || time=='a')) h=0;
else if (h!=12 && (time=='P' || time=='p')) h+=12;
so if you give input 1:30 AM
both of the condition become false .So it just print the input 01:30 .(here printf("%02d") means it will give atleast 2digit output).
+ 3
Welcome 🤗
+ 2
Arsenic what happens if I input 1:30 AM as a input...[here h != 12 && time == 'A']
Can you please explain related to this input?
+ 2
😃
0
Basically scanf takes value from the user.in the second program as you can see its written in a single scanf it's used to take many inputs without typing scanf too many of times