如何将出生日期的hypen插入日期字符串?

时间:2017-04-23 21:31:50

标签: c arrays string append

如何将hypen插入到这样的字符串中 01201997

并将其设为01-20-1997

到目前为止,我有这个

void datef(char string[])
{
    char strFinal[50];

    char *strB = "/", *strA[3]; // declare two strings you will join plus a third string to put in
    int x = 3; // declare integer to tell program how many characters you want to insert your string into
    int y = 5;
    strncpy(strFinal,string,x);// copies the first X characters into the strC, you have to add the null
    strFinal[x] = '\0'; // adds the null
    strcat(strFinal,strB); // copies the second half of the string
    strcat(strFinal,string+x); // another part to copy the remaining part of the string
    strncpy(strFinal, string, x);
    printf("%s\n",strFinal); // prints string
}

0 个答案:

没有答案