函数 isdigit 可以用一个字符来调用,但是如果我们发送一个带有 255 十进制数的位“&”,为什么我们要这样做呢?我从 c 中的示例中找到了这一点
const char *value =1234567890abcdefghijklm";
for(i=0; value[i]; i++) {
int r1 = isdigit(value[i]);
int r2 = isdigit(value[i]&0xFF);
printf("%d %d\n", r1,r2);
Run Code Online (Sandbox Code Playgroud)
如果我输出上面的内容,我看不到 r1 和 r2 之间的区别
2048 2048
2048 2048
2048 2048
2048 2048
2048 2048
2048 2048
2048 2048
2048 2048
2048 2048
2048 2048
0 0
0 0
0 0
0 0
0 0
0 0
0 0
Run Code Online (Sandbox Code Playgroud)
0 0 0 0 0 0 0 0 0 0 0 0
为什么要将该值屏蔽 255(1 字节)?
我正在使用 fscanf 从这种格式的文件中获取名称和号码并将其打印出来:
Jim: 100.00
John: 200.00
Adam: 300.00
Miguel: 400.00
Run Code Online (Sandbox Code Playgroud)
我的输出没有正确打印。
我尝试过使用while(fscanf(filep, "%s %lf", name, balance) != EOF),但它似乎总是以这种格式打印:
Jim:: 0.0000
John:: 0.0000
Adam:: 0.0000
Miguel:: 0.0000
Run Code Online (Sandbox Code Playgroud)
看起来它正确地读取了名称,但它在名称末尾添加了冒号(我在 printf 中有一个冒号,所以我想避免额外的冒号),但它不能正确读取数字。我不太确定我能做些什么来解决这个问题,所以我们将不胜感激。