[ create a new paste ] login | about

Link: http://codepad.org/eCbQbPAR    [ raw code | output | fork ]

appunti2 - C, pasted on Apr 30:
#include <stdio.h>

#define STRNCPY(DST, ORG, N) { \
    char *s1 = (DST); \
    const char *s2 = (ORG); \
    size_t n = (N); \
    int i; \
    for (i = 0; i < n && s2[i] != 0; i++) \
      { \
        s1[i] = s2[i]; \
      } \
    s1[i] = 0; }

int main (void)
{
  char stringa[100];
  STRNCPY (stringa, "Buon giorno a tutti!", 50)   // [1]
                            // [1] Si osservi che manca il
                            //     punto e virgola finale!
  printf ("%s\n", stringa);
  return 0;
}


Output:
1
Buon giorno a tutti!


Create a new paste based on this one


Comments: