Advertisement
Keith_S_Thompson

Example for http://blog.surgut.co.uk/2015/08/go-enjoy-python

Aug 27th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. /*
  2.  * Reference: http://blog.surgut.co.uk/2015/08/go-enjoy-python3.html
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. #define LEN 12
  10.  
  11. int main(int argc, char *argv[]) {
  12.     char res[LEN+1];
  13.  
  14.     if (argc != 2) {
  15.         fprintf(stderr, "Usage: %s string\n", argv[0]);
  16.         exit(EXIT_FAILURE);
  17.     }
  18.  
  19.     /*
  20.      * strncat() onto an empty string behaves the way
  21.      * strncpy() arguably _should_ behave
  22.      */
  23.     res[0] = '\0';
  24.     strncat(res, argv[1], LEN);
  25.     puts(res); /* or printf("%s\n", res) if you prefer */
  26.     return 0;  /* optional in C99 or later */
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement