小编Chr*_*ris的帖子

比较两个文件

我正在尝试编写一个比较两个文件内容的函数.

我希望它在文件相同时返回1,如果不同则返回0.

ch1ch2作为缓冲区,我曾经fgets获取我的文件的内容.

我认为eof指针有问题,但我不确定.FILE变量在命令行中给出.

PS它适用于大小低于64KB的小文件,但不适用于较大的文件(例如700MB电影,或5MB的.mp3文件).

任何想法,如何解决?

int compareFile(FILE* file_compared, FILE* file_checked)
{
    bool diff = 0;
    int N = 65536;
    char* b1 = (char*) calloc (1, N+1);
    char* b2 = (char*) calloc (1, N+1);
    size_t s1, s2;

    do {
        s1 = fread(b1, 1, N, file_compared);
        s2 = fread(b2, 1, N, file_checked);

        if (s1 != s2 || memcmp(b1, b2, s1)) {
            diff = 1;
            break;
        }
      } while (!feof(file_compared) || !feof(file_checked));

    free(b1); …
Run Code Online (Sandbox Code Playgroud)

c++

10
推荐指数
4
解决办法
3万
查看次数

这段代码是什么?

我试图理解这段代码的用途,但我无法理解.你能解释一下吗?

co_to(I, I, [I]).

co_to(I, L, [I|L]) :- I < K, I1 is I + 1, co_to(I1, K, L).
Run Code Online (Sandbox Code Playgroud)

prolog

1
推荐指数
1
解决办法
91
查看次数

通过stat()函数传递字符串

我有以下代码:

#include <stdio.h>       // For printf()
#include <sys/stat.h>   // For struct stat and stat()

struct stat stResult;

if(stat("Filename.txt", &stResult) == 0)
{
      // We have File Attributes
      // stResult.st_size is the size in bytes (I believe)
      // It also contains some other information you can lookup if you feel like it
printf("Filesize: %i", stResult.st_size);
}
else
{
      // We couldn't open the file
printf("Couldn't get file attributes...");
}
Run Code Online (Sandbox Code Playgroud)

现在.如何通过stat()传递我自己的字符串?像这样

string myStr = "MyFile.txt";
stat(myStr, &stResult)
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
1483
查看次数

标签 统计

c++ ×2

prolog ×1