[Solved] Unexpected output of printf for a string in C
None of those two cases are right. Case 1 only worked because you got lucky, probably by giving a short string as input. Try something like “bfjabfabjkbfjkasjkvasjkvjksbkjafbskjbfakbsjfbjasbfjasbfkjabsjfkbaksbfjasbfkja” and you’ll suffer a seg fault, most likely. You should have a block of memory associated with str, either on the stack by declaring an array for it … Read more