use of while loop in strncpy function

This commit is contained in:
Divyesh Dhole 2022-12-30 19:22:20 +05:30 committed by GitHub
commit 0c23d50bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,14 +16,14 @@
size_t size_t
sc_strncpy(char *dest, const char *src, size_t n) { sc_strncpy(char *dest, const char *src, size_t n) {
size_t i; size_t i=0;
for (i = 0; i < n - 1 && src[i] != '\0'; ++i) while(i < n - 1 && src[i] != '\0')
dest[i] = src[i]; dest[i] = src[i++];
if (n) if (n)
dest[i] = '\0'; dest[i] = '\0';
return src[i] == '\0' ? i : n; return src[i] == '\0' ? i : n;
} }
//use of while loop insted of using for loop
size_t size_t
sc_str_join(char *dst, const char *const tokens[], char sep, size_t n) { sc_str_join(char *dst, const char *const tokens[], char sep, size_t n) {
const char *const *remaining = tokens; const char *const *remaining = tokens;