| Uutiset | Koodikirjasto | Wiki | Keskustelut | FAQ | Info |
strnsetTorak 04.11.02 12:24 Asettaa merkkijonosta ensimmäiset n merkkiä halutuiksi.
#include <windows.h> #include <stdio.h> //============================================================================= // Function..: strnset (Borland specifid string function). // Purpose...: Sets a specified number of characters in a string to a given // character. strnset copies the character ch into the first n // bytes of the string s. If n > strlen(s), then strlen(s) // replaces n. It stops when n characters have been set, or // when a null character is found. // Return....: s //============================================================================= LPTSTR strnset(LPTSTR s, TCHAR ch, DWORD n) { while(*s && n) { *s = ch; n--; s++; } return s; } vade 07:27 8.11.02 strnset-funktion pitäisi palauttaa osoitin stringin alkuun. Funktiosi palauttaa osoittimen asetettujen merkkien perään. Looppia voisi hieman puristaa nätimmäksi: while (*s && n--) *s++ = ch; |
![]() Haku
|