Recently I participated in an interview where they added two strings without using strcat () Asked to write the C program.
, strlen ()
and strcmp ()
and that function should not exceed two (2) lines.
I know how to insert two strings without using strcat ()
but there are about 15 lines in my method, I do not know how to write it in two rows .
I hope they want to do something like this:
Void mystrcat (char * dest, const char * src) {// Advance Guidelines As long as we (* dost) ++ dest; // Done the copy with the cancellation of the source, as long as we did not hit src // at the end of editing: basically it: // for (; * dest = * src, * src; ++ dest, ++ src); // ... which is similar to this (; * dest = * src; ++ dest, ++ src); }
This does not return the end of the concerted string to the actual strcat
, but it does not seem necessary.
I do not necessarily know whether this type of thing is a good interview question - it shows that you can completely code, and you know that strcat
What does, but it's about it.
Edit: As AB writes, the statement
while (* dest ++ = * src ++);
... is probably a more traditional way of writing another loop (rather than using for
).
Comments
Post a Comment