#include<stdio.h>
#include<string.h>
int YenCov(int, int, char *, int);
int main(void) {
int kingaku;
int mode;
int datsize;
int rtn;
char kindat[15];
rtn = YenCov(kingaku, mode, kindat, datsize);
if (rtn == -1) {
} else if (rtn == -2) {
} else {
printf("編集金額 = %s\n", kindat
); }
return 0;
}
int YenCov(int kin, int md, char *bp, int size) {
char buf1[15]; /* 対象データ格納用 */
char buf2[15]; /* \マーク編集結果を格納 */
int len; /* 対象データ文字数格納用 */
int cmcnt; /* 挿入カンマ数カウンタ */
int cnt; /* コピー文字数カウンタ */
int i, j;
cnt = 0;
if (md != 1 && md != 2) {
return -1;
}
sprintf(buf1
, "\\%d", kin
); /* 金額を文字列としてbuf1に格納 */
if (md == 1) {
cmcnt = 0;
} else {
cmcnt = (len - 2) / 3;
}
if (len + cmcnt + 1 > size) {
return -2;
}
if (md == 1) {
} else {
buf2[len + cmcnt] = '\0';
for (i = len - 1; i >= 0; i--) {
j = i + cmcnt;
if (cnt == 3 && cmcnt != 0) {
/* ①番 カンマ代入 */
buf2[j] = ',';
cnt = 0;
cmcnt--;
/* ②番 添え字の更新 */
j--;
}
/* ③番 数値文字の結果の代入 */
buf2[j] = buf1[i];
cnt++;
}
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CgppbnQgWWVuQ292KGludCwgaW50LCBjaGFyICosIGludCk7CgppbnQgbWFpbih2b2lkKSB7CiAgaW50IGtpbmdha3U7CiAgaW50IG1vZGU7CiAgaW50IGRhdHNpemU7CiAgaW50IHJ0bjsKICBjaGFyIGtpbmRhdFsxNV07CgogIHByaW50Zigi6YeR6aGN5YWl5YqbPT0+Iik7CiAgc2NhbmYoIiVkIiwgJmtpbmdha3UpOwoKICBwcmludGYoIuODouODvOODiSgxIG9yIDIpPT0+Iik7CiAgc2NhbmYoIiVkIiwgJm1vZGUpOwoKICBwcmludGYoIuODh+ODvOOCv+OCteOCpOOCuj09PiIpOwogIHNjYW5mKCIlZCIsIC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