[ create a new paste ] login | about

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

C, pasted on Aug 30:
#include<stdio.h>

int main(){
    const char* text  = "123:234:345:567:768:aaa:bbb:ccc:ggg:ttt:ddd";
    char  tx[100][4];
    int i, j;
    char* p;

    p = text;

    /* 切り出し */
    for( j = 0; j < 100; j++ ){

        /* 最大3文字までコピー */
        for( i = 0; (i < 3) && (*p != '\0') && (*p != ':'); i++ ){ 
            tx[j][i] = *p++;
        }

        /* 終端記号の付加 */
        tx[j][i] = '\0';

        /* 切りだし元が終端に到達 */
        if(*p == '\0'){ break; }

        /* ':'の分 */
        p++;
    }

    /* 切りだし後の確認表示 */
    for( i = 0; i <= j; i++ ){
        printf("tx[%2d] = %s\n",i,tx[i]);
    }

    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
tx[ 0] = 123
tx[ 1] = 234
tx[ 2] = 345
tx[ 3] = 567
tx[ 4] = 768
tx[ 5] = aaa
tx[ 6] = bbb
tx[ 7] = ccc
tx[ 8] = ggg
tx[ 9] = ttt
tx[10] = ddd


Create a new paste based on this one


Comments: