How can changing the size of the string to be scanned affect the output completely independent of it? -


my code giving wrong answer on problem 400a on http://codeforces.com while working fine on laptop. suggested me problem can solved increasing size of string , after doing that, code got accepted. find mistake in original code, placed print statements in 2 codes find out going wrong , made 2 submissions in codeforces. in following submissions, changed size of array w 12 13: http://codeforces.com/contest/400/submission/5948686

http://codeforces.com/contest/400/submission/5948717

as can see, in former case, inner loop not executed i=0 in later case is. why happening (i know string size must kept greater string how related functioning of inner loop @ i=0)?

here's best guess, depends on compiler used, how memory way laid out, - there may no way know sure. else may have better guess.

so here's maybe happened: scanf read in 13 characters - 12 characters, plus null terminating character (\0). null terminator has ascii value of 0

the 12 characters thrown buffer correctly, , \0 character maybe overwrote first value of ar. inner loop became for(j=0; j < 0; j++)

moral of story buffer overflows bad.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -