Why I'm getting different output in different compilers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why I'm getting different output in different compilers?

See c style strings comparison... Input *Saurabh Kumar* In a compiler i got -1, 83 In another i got -115, 115 Why and how??? See and please tell me... https://code.sololearn.com/cMuAdE5Kr2a7/?ref=app

19th May 2021, 12:27 PM
saurabh
saurabh - avatar
4 Answers
+ 3
This is because of how strcmp() is implemented by your compiler implementation. Standards only specify that this function should either return a 0 ( for equality ), negative number (when the first character that does not match has a lower value in ptr1 than ptr2) or a positive number otherwise.
19th May 2021, 3:52 PM
Arsenic
Arsenic - avatar
+ 3
This way I constantly get (-32) and (32) from `strcmp`. `strcmp` returns non zero here because <temp> contains the same letters to those in <full_name>, but in different case (<temp> has uppercase version). The result (32) and (-32) resulted from the distance between the first `char` found to be different (at same index) in both C-string. (Edited)
19th May 2021, 2:47 PM
Ipang
+ 1
$|<|>_α& You haven't stored anything into <temp> and yet you are comparing <temp> and <full_name>. Check what you got in <temp> and ask yourself whether that comparison was in order.
19th May 2021, 2:22 PM
Ipang
+ 1
Ipang ohh sorry!!! ok ,,, Modified now...... Now look in to that and consider my problem
19th May 2021, 2:33 PM
saurabh
saurabh - avatar