0

我正在尝试将字符串解码为其内容,但程序输出与预期不符。输出是:

-858993623 444 333

什么是-858993623?

#include <stdio.h>

int main(void){

int areaCode;
long phoneNumber1;  
long phoneNumber2;
char bracket1, bracket2, chard;

char tel[]="(555) 444-333";

sscanf(tel, "%c%d%c %ld%c%ld", &bracket1, &bracket2,  &areaCode, &phoneNumber1, &chard, &phoneNumber2 );

printf("%d %ld %ld", areaCode, phoneNumber1, phoneNumber2);

getch();

}

4

1 回答 1

2

您目前处于 UB 领域:尝试&bracket1, &areaCode, &bracket2 而不是&bracket1, &bracket2, &areaCode. 其他一切看起来都很好。

于 2013-09-09T12:29:17.317 回答