How to copy string with snprintf() in C

2 Answers

0 votes
#include <stdio.h>

int main(void)
{
    char n[] = "01234567890";
    char s[13] = "";

    snprintf(s, sizeof(n), "%s", n);

    puts(s);

    return 0;
}




/*
run:

01234567890

*/

 



answered Aug 4, 2017 by avibootz
edited Aug 5, 2023 by avibootz
0 votes
#include <stdio.h>

int main(void)
{
    char n[] = "c c++ c# java";
    char s[32] = "";

    snprintf(s, sizeof(n), "%s", n);

    puts(s);

    return 0;
}



/*
run:

c c++ c# java

*/

 



answered Aug 4, 2017 by avibootz
edited Aug 5, 2023 by avibootz

Related questions

1 answer 110 views
1 answer 122 views
1 answer 273 views
273 views asked Jan 26, 2016 by avibootz
...