First of all congrates to Guru and Prabhat for their perfect explanation to CODIES 1.1. You will get your treat (I am sorry for such a delay ) along with the winner of CODIES 1.3, the next post. I am sure you gonna love the next question, it's a good one. Right now here i am up with one another question - CODIES 1.2:-
int main()
{
printf("%s", "technoprax");
return 0;
}
Que : Output "prax" from the above code snippet. You are allowed only to add/replace 2 characters in the code.
int main()
ReplyDelete{
printf("%s\r ","technoprax");
return 0;
}
Sorry Anshika, but your solution doesn't seem to work. We need to output "prax". Adding a "\r" after "%s", brings the cursor back to starting of the line after printing the string.
ReplyDeleteafter \r I had put 6 spaces which are not visible in my comment...will that be valid?
ReplyDeleteohk. Good approach. But the problem clearly states that we are allowed only to add/replace only 2 characters.Solution is very, just look at the basics.
ReplyDeleteOkey...This works...
ReplyDeleteThe two changes suggested in the code are :
1.Delete 'n'
2.Replace 'o' with '\r'
int main()
{
printf("%s", "tech\rprax");
return 0;
}
Thanx anshika for bringing that \r into the scene...cool thing :)
int main()
ReplyDelete{
printf("%s", "techno\rprax");
return 0;
}
-HITANSHU
here is my code
ReplyDeleteint main()
{ clrscr();
printf("%s","tech\rprax");
getch();
return 0;
}
i have replaced 2 characters "no" with "\r".
and the output is "prax"
Ok guys, its gud to see you all brainstorming.
ReplyDelete@Pravy, Hitman and Akank : your answers are right. They do output "prax". But "\r" was not what I wanted to highlight through this post. :)
The most correct solution to this question is very basic and highlights some intricacies of C. You all know the answer, its just that you are not aware of it. :)
Enjoy Coding !!!
int main()
ReplyDelete{
printf("%s","technoprax"+6);
return 0;
}
Congrates prabhat, that is the right answer. This was what I was trying to highlight in this question. Please explain your answer.
ReplyDeletewhile outputting a string using %s the option "+n" helps us to skip 'n' characters from beginning of the string supplied & displays the rest of the string.
ReplyDeleteint main()
ReplyDelete{
printf("%s", "{techno}prax");
return 0;
}
P.S. I'm a chemical engg...:P
ReplyDelete@V : sorry, your solution is wrong.
ReplyDelete@prabhat : I think we can relate it with starting address of string and shifting it. Just a guess...
ReplyDelete