我一直在嘗試很長時間來弄清楚如何讓程序從文件中讀取文本。我已經嘗試過使用fgets()和循環的解決方案。程序運行但不打印變量,表明文本未被提取。我不能得到fread()將文件內容打印到字符串變量
#include <stdio.h>
#include <string.h>
#include "stdfn.h"
int main(int argc, char* argv[])
{
char* request;
char bf_text[1024];
char character;
intro("Site Blocker", 2014, "MIT");
request = bash("curl http://redsec.ru/blocked_sites.txt"); // Source of bash() is at line 139 https://github.com/Pavelovich/lib-c/blob/master/stdfn.h
//printf("%s", request);
FILE* block_file = fopen(".blocked_sites", "w+"); // Changed from "w" based on this thread, currently only outputs a small part of the file.
FILE* hosts = fopen("hosts", "w");
FILE* hosts_tmp = fopen(".hosts", "w");
// Print the text of the web request to the temporary
// .blocked_sites file
fprintf(block_file, "%s", request);
rewind(block_file);
fread(bf_text, sizeof(block_file), 1, block_file);
printf("%s", bf_text);
fclose(block_file);
return 0;
}
'fread(bf_text ...','bf_text'沒有以''\ 0''結尾, – chux 2014-10-09 01:35:16
那麼我需要使它成爲'sizeof(block_file)+ 1'? – 2014-10-09 01:46:26