C语言关于fscanf的有关问题

C语言关于fscanf的问题
目前只学过C和JAVA,然后这学期有个工程实践是让用任何一种语言写DES算法的加密解密。考虑到JAVA学的不怎么好,然后在晚上看到说C在这种数的运算上要更快,所以就用C写的DES加密解密。

最初写的解密算法需要输入密文(64bit),考虑到输入的数据太长,所以想改用文件。

现在写成的结果就是,将加密好的密文通过fprintf写入到 in.text 文件中。解密的时候用fscanf从 in.text 文件中直接读取,然后解密。

一开始我写的是  fprintf(fp1,"%d",output[i]);  发现可以将数据写入到文件中,但如果使用   fscanf(fp1,"%d",&ctext[i]);  读取数据,则数据读取不到。

但如果将两个都改成  fprintf(fp1,"%d\n",output[i]);   和   fscanf(fp1,"%d\n",&ctext[i]);   则写入文件和读取文件都是正常的。

所以,为什么加了一个换行符就正确了?

另外,如果有个for循环,每次fscanf读取两个字符,例如fscanf(fp1,"%d\n%d\n",&a,&b);  然后读取的文件里的数据是1\n2\n3\n4\n,那么第一次读取是读取的1  2   第二次就是读取3 4吗? 

再另外,关于DES算法实现的一个问题,听说DES算法的好代码都是用 布尔型 的数组保存的二进制数,记得同学说的貌似是因为布尔型运算快一些。这是为什么呢?对于布尔型懂得不多。有了解的人麻烦大体讲一下吧。

谢谢各位了。
------解决方案--------------------
一开始我写的是  fprintf(fp1,"%d",output[i]);  发现可以将数据写入到文件中,但如果使用   fscanf(fp1,"%d",&ctext[i]);  读取数据,则数据读取不到。
比如你写入1到9的值 文本中存入为123456789,试问一下如果你写入的太多 怎么用fscanf读到数据呢?说白了就是你没有存入数据的个数 若你加入了换行或者空格等等能识别的符号 当然不包括数字 比如fprintf(fp1,"%d ",output[i])再用fscanf(fp1,"%d ",&ctext[i])也能正确读到你存入的数据 这样也就解决你第二问的问题了
至于用bool类型能快一些,个人认为快不了多少(甚至不会快,可能是多此一举吧,个人意见),虽然DES算法中用到的与或等操作多,但试想一下 比如3和8求或操作 他们在计算机中存入的方法本来就是2进制,你用bool类型也是2进制,这样就没有加快你的算法等等,如果想加快 还是建议从算法上改进吧
------解决方案--------------------
仅供参考
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "advapi32.lib")
#define _WIN32_WINNT 0x0400
#include <stdio.h>
#include <windows.h>
#include <wincrypt.h>
#define MY_ENCODING_TYPE  (PKCS_7_ASN_ENCODING 
------解决方案--------------------
 X509_ASN_ENCODING)
#define KEYLENGTH  0x00800000
void HandleError(char *s);
//--------------------------------------------------------------------
//  These additional #define statements are required.
#define ENCRYPT_ALGORITHM CALG_RC4
#define ENCRYPT_BLOCK_SIZE 8
//   Declare the function EncryptFile. The function definition
//   follows main.
BOOL EncryptFile(
    PCHAR szSource,
    PCHAR szDestination,
    PCHAR szPassword);
//--------------------------------------------------------------------
//   Begin main.
void main(void) {
    CHAR szSource[100];
    CHAR szDestination[100];
    CHAR szPassword[100];
    printf("Encrypt a file. \n\n");
    printf("Enter the name of the file to be encrypted: ");
    scanf("%s",szSource);
    printf("Enter the name of the output file: ");
    scanf("%s",szDestination);
    printf("Enter the password:");
    scanf("%s",szPassword);
    //--------------------------------------------------------------------
    // Call EncryptFile to do the actual encryption.
    if(EncryptFile(szSource, szDestination, szPassword)) {
        printf("Encryption of the file %s was a success. \n", szSource);
        printf("The encrypted data is in file %s.\n",szDestination);
    } else {
        HandleError("Error encrypting file!");
    }
} // End of main
//--------------------------------------------------------------------
//   Code for the function EncryptFile called by main.
static BOOL EncryptFile(
    PCHAR szSource,
    PCHAR szDestination,
    PCHAR szPassword)
//--------------------------------------------------------------------
//   Parameters passed are:
//     szSource, the name of the input, a plaintext file.
//     szDestination, the name of the output, an encrypted file to be
//         created.
//     szPassword, the password.
{
    //--------------------------------------------------------------------
    //   Declare and initialize local variables.
    FILE *hSource;
    FILE *hDestination;
    HCRYPTPROV hCryptProv;
    HCRYPTKEY hKey;
    HCRYPTHASH hHash;
    PBYTE pbBuffer;
    DWORD dwBlockLen;
    DWORD dwBufferLen;
    DWORD dwCount;