CYB3Rhuman

Untitled

Jun 30th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.    char *a = "12 34 56";
  8.    int a_l = strlen(a);
  9.    printf("str1: \"%s\" (%d)\n", a, a_l);
  10.  
  11.    char *b = "___";
  12.    int b_l = strlen(b);
  13.    printf("str2: \"%s\" (%d)\n", b, b_l);
  14.  
  15.    for (int i = 0; i < a_l; i++) {
  16.       if (a[i] == ' ') {
  17.          char *o = malloc(a_l + b_l);
  18.          
  19.          strncpy(o, a, i);
  20.          strncpy(o + i, b, a_l);
  21.          //strncpy help
  22.  
  23.          printf("out:  \"%s\"\n", o);
  24.       }
  25.    }
  26.  
  27.    return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment