what's wrong with my one-liner strncpy: while(*s++ = *t++ && n-- > 0);?

Posted by pvd on Stack Overflow See other posts from Stack Overflow or by pvd
Published on 2013-10-24T03:44:47Z Indexed on 2013/10/24 3:54 UTC
Read the original article Hit count: 132

Filed under:
#include <stdio.h>
#define STR_BUF    10000
#define STR_MATCH  7

void mystrncpy(char* s, char* t, int n) {
    while(*s++ = *t++ && n-- > 0);
}

int main() {
    int result;
    char str_s[STR_BUF] =  "not so long test string";
    char buf_1[STR_BUF];
    mystrncpy(buf_1, str_s, STR_MATCH);
    printf ("buf_1 (mystrncpy, 7 chars): %s\n", buf_1);
    return 0;
}

When I run it, nothing happened

ian@ubuntu:~/tmp$ gcc myncpy.c -o myn&&./myn
buf_1 (mystrncpy, 7chars):

© Stack Overflow or respective owner

Related posts about c