[ create a new paste ] login | about

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

C, pasted on May 5:
#include <stdio.h>
#include <string.h>
 
int main(){
    int i, j, k, size, count; 
    const char srow[] = "1234567890123456789";
    const char ssub[] = "<sub text>";
    char sout[4096]   = {0};
    printf("text row : %s\n", srow);
    printf("text sub : %s\n", ssub);
    size = strlen(srow);
    count= strlen(ssub);
    for( i = 0, j = 2, k = 0; i < size; i++, k++ )
    {
        if( i == j )
        {
            j = j * 2;
            strcpy(&sout[k], ssub);
            k = k + count;
        }
        sout[k] = srow[i];
    }
    printf("text out : %s\n", sout);
    return 0;
}


Output:
1
2
3
text row : 1234567890123456789
text sub : <sub text>
text out : 12<sub text>34<sub text>5678<sub text>90123456<sub text>789


Create a new paste based on this one


Comments: