From 0c23d50bdf410b572bc524cf1ff6dcea1493a3eb Mon Sep 17 00:00:00 2001 From: Divyesh Dhole <114863603+divyeshdhole@users.noreply.github.com> Date: Fri, 30 Dec 2022 19:22:20 +0530 Subject: [PATCH] use of while loop in strncpy function --- app/src/util/str.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/util/str.c b/app/src/util/str.c index d78aa9d7..811c2024 100644 --- a/app/src/util/str.c +++ b/app/src/util/str.c @@ -16,14 +16,14 @@ size_t sc_strncpy(char *dest, const char *src, size_t n) { - size_t i; - for (i = 0; i < n - 1 && src[i] != '\0'; ++i) - dest[i] = src[i]; + size_t i=0; + while(i < n - 1 && src[i] != '\0') + dest[i] = src[i++]; if (n) dest[i] = '\0'; return src[i] == '\0' ? i : n; } - +//use of while loop insted of using for loop size_t sc_str_join(char *dst, const char *const tokens[], char sep, size_t n) { const char *const *remaining = tokens;