??? 07/23/04 13:40 Read: times |
#74750 - RE: What do you doubt? Responding to: ???'s previous message |
"Well, it is right except that generally, sprintf() should not be used for string copying."
Sure, strcpy() or strncpy() would be the obvious choices. sprintf() however does provide the %s conversion specifier making sprintf(dest,"%s",source) a perfectly legitimate way of copying a string. "When somebody uses sprintf() he must understand what he does." Sure, same with strcpy() or any other library function. "It is why I mentioned that sprintf() has nothing with "source" and "destination", it uses "buffer" and "format string" instead." The first parameter of sprintf() most certainly is the destination for its output. You are welcome to call it buffer, destination, target or whatever you like. Here's the prototype from the 'C' standard: int sprintf(char *s, const char *format, ...) As you can see they have chosen the rather exciting label 's'. "Moreover, I do not see a reason why it is need to use huge and complex sprintf() for string copy although there is quick and simple strcpy()." I can suggest one possibility: If you have used sprintf() elsewhere in your code then the function is already linked. If you then use strcpy() as well you're linking extra library code. If code size is an issue there may be some benefit. "By the way, it is good example why programming requires keep track of correct usage of the terms and definitions: - if I need modify string with format sequence then I use sprintf(). Letter "f" at the end of function name indicates "formating process"; - if I need to copy string (even if it is format string itself) then I use strcpy()." If you really want to be really picky the only references I can find define the 'f' as meaning 'formatted'. |
Topic | Author | Date |
doub about strutc pointers | 01/01/70 00:00 | |
RE: doub about strutc pointers | 01/01/70 00:00 | |
RE: doub about strutc pointers | 01/01/70 00:00 | |
What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
RE: undefined behaviour land | 01/01/70 00:00 | |
RE: What do you doubt? | 01/01/70 00:00 | |
Still unknown doubt | 01/01/70 00:00 | |
RE: doub about strutc pointers | 01/01/70 00:00 | |
Nothing 8051-specific here | 01/01/70 00:00 | |
RE: Nothing 8051-specific here | 01/01/70 00:00 | |
RE: doub about strutc pointers | 01/01/70 00:00 | |
RE: doub about strutc pointers![]() | 01/01/70 00:00 |