首页 > 用户发贴区 > 编程问题提问区 > [求助]關於fgetc的疑問
2008
01-14

[求助]關於fgetc的疑問

我發現用fgetc函數,儅讀取到的數據為7F以下的時候,很正常,但是儅數據為7F以上,就發生問題了,我猜想是因爲char的範圍就是0~7F,請問,有什麽辦法可以解決7F以上數據的讀取,附上我的程序:
#include <stdio.h>


void main(int argc, char *argv[]) {
    FILE *fp;
    char content;
    int offset;
 int i=0;
    if (argc == 1 || argc > 4) {
     printf(“Usage:\n”);
  printf(“tool-path target-path                 :display length & content of the target file\n”);
  printf(“tool-path target-path offset          :display content of the target file at the offset\n”);
  printf(“tool-path target-path offset hex_data :write the hex_data into the offset of the target file”);
 } else if (argc >=2 && argc <=4) {
  fp = fopen(argv[1], “rb+”);
        if (fp != NULL) {
   if (argc == 2) {
                fseek(fp, 0, 2);
    offset = ftell(fp);
    printf(“target file’s size: %d byte\n\n”, offset);
    rewind(fp);
    content = fgetc(fp);
    while (content != EOF) {
     if (i == 16) {
      printf(“\n”);
      i = 0;
     } else {
                        printf(“%x “, content);
      content = fgetc(fp);
      i++;
     }
    }


   } else if (argc == 3) {
       sscanf(argv[2], “%d”, &offset);
       fseek(fp, offset, 0);
       content = fgetc(fp);
       printf(“offset=%x,content=%x\n”,offset, content);
   } else if (argc == 4) {


            }
  } else {
      printf(“can’t open the target file %s”, argv[1]);
  }
  fclose(fp);
 }
}


[求助]關於fgetc的疑問》有 1 条评论

留下一个回复