你好我想用一个文件输入流或某种阅读这样的文字:阅读本书在C/C++
E^@^@<a^[email protected]^@@^FÌø<80>è^AÛ<80>è ^F \^DÔVn3Ï^@^@^@^@ ^B^VÐXâ^@^@^B^D^E´^D^B^H
IQRÝ^@^@^@^@^A^C^C^GE^@^@<^@^@@^@@^F.^K<80>è ^F<80>è^AÛ^DÔ \»4³ÕVn3Ð ^R^V J ^@^@^B^D^E´^D^B^H
^@g<9f><86>IQRÝ^A^C^C^GE^@^@4a^[email protected]^@@^FÌÿ<80>è^AÛ<80>è ^F \^DÔVn3л4³Ö<80>^P^@.<8f>F^@^@^A^A^H
IQRÞ^@g<9f><86>E^@^A±,[email protected]^@@^F^@E<80>è ^F<80>è^AÛ^DÔ \»4³ÖVn3Ð<80>^X^@.^NU^@^@^A^A^H
^@g<9f><87>
这是我试图用读它的代码,但我得到了一堆为0。
#include <stdio.h> /* required for file operations */
int main(int argc, char *argv[]){
int n;
FILE *fr;
unsigned char c;
if (argc != 2) {
perror("Usage: summary <FILE>");
return 1;
}
fr = fopen (argv[1], "rt"); /* open the file for reading */
while (1 == 1){
read(fr, &c, sizeof(c));
printf("<0x%x>\n", c);
}
fclose(fr); /* close the file prior to exiting the routine */
}
我的代码出了什么问题?我想我没有正确读取文件。
什么是文件的编码? UTF8? Unicode的? – rkosegi 2012-01-13 05:34:08
我不知道,你该怎么做? – SuperString 2012-01-13 05:37:00
等等,你使用'FILE *'并将它传递给'read()'? 'read()'需要一个'int fd',除非这是一个不是的平台? – 2012-01-13 05:40:30