字符串分割

字符串分隔

http://www.nowcoder.com/questionTerminal/d9162298cb5a437aad722fccccaae8a7

思路

这题没啥好说的。
按照8字符的长度截取,不足的补'0'
用标准库的string函数比较方便

#include<stdio.h>
#include<string.h>

#define MAX_SIZE 100
#define OUTPUT_SIZE 8

int main()
{
    char str[MAX_SIZE + 1] = "";
    char tempStr[OUTPUT_SIZE  + 1] = "";
    char *tempPonit = 0;

    while (scanf("%s", str) != EOF) {
        tempPonit = str;
        while (*tempPonit) {
            memcpy(tempStr, tempPonit, sizeof(tempStr) - 1);
            memset(tempStr + strlen(tempStr), '0', sizeof(tempStr) - 1 - strlen(tempStr));
            tempPonit += strlen(tempStr);
            printf("%s\n", tempStr);
        }

        memset(str, 0, sizeof(str));
        tempStr[8] = '\0';

    }
    return 0;
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务