int countBouncy=5;
int count=999899;
double percent = (double)(countBouncy / count) * 100.0;
Run Code Online (Sandbox Code Playgroud)
这句话的结果出乎意料,我得零.
为什么它不起作用?
按位运算的有符号和无符号变量之间有什么区别吗?
例如,处理无符号数时:
AND 00000111, 00001101
将导致00000101.
但是在处理签名号码时会发生什么?
我有这个代码:
while( (cCurrent = fgetc(fp)) != EOF)
{
}
Run Code Online (Sandbox Code Playgroud)
问题是,当它遇到一个新行时,它会停止阅读.
什么是忽略换行符的好方法?
编辑:
我正在尝试创建一个文件控制器.它能够加密文件,但解密过程不起作用.它一直工作到第一行结束,但它不会继续到文件中的下一个字符.
例如,对于文本文件:
Foo
Bar
Run Code Online (Sandbox Code Playgroud)
加密后,结果是:
徐||千兆| T
解密后,结果是:
Run Code Online (Sandbox Code Playgroud)FooRqb
我得出结论,新线char是问题所在.也许不是.
我的代码是:
/* check if the file is openable */
if( (fp = fopen(szFileName, "r+")) != NULL )
{
/* save current position */
currentPos = ftell(fp);
/* get the current byte and check if it is EOF, if not then loop */
while( (cCurrent = fgetc(fp)) != EOF)
{
/* XOR it */
cCurrent ^= 0x10;
/* take …Run Code Online (Sandbox Code Playgroud) 我知道在面向对象语言中使用静态变量的目的是什么,但是,我不明白在C中使用"static"关键字的含义是什么.有人能解释一下吗?