user-0 提问: 求指导！我想从TXT文本中读取第一行乱码，并把这行乱码存到数组

回复:
user: user-1
content: 用二进制方式读取该文本，是不是就达到你的要求了？类似如下的代码#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) {     FILE * fp;     int i,len;     char *filename = "E:/test.txt";     char str[128];     memset(str,0,sizeof(str));     if( (fp=fopen(filename,"rb"))== NULL )     {         printf("Can not open %s!\n",filename);         exit(0);     }     i = 0;     while(!feof(fp))     {         str[i++] = getc(fp);     }     fclose(fp);     len = i;     for(i = 0; i < len; i++)         printf("%c",str[i]);     printf("\n");     return 0; }

user: user-2
content: 建议参考下 林锐 《高质量c、c++编程指南》

user: user-2
content: 没什么心思看，楼主变量名取的太随意了，谭浩强的风格！

user: user-0
content: 上面代码是从csv文件和一个文本中读取数据，其中csv跳过第一行从第二还开始提取并进行加密后输出到一个文本文件中。文件名字自己取的，还有一下文件名字命名处理。然后最下面才是开始从文本中读取乱码数据。用QT写的，里面混合了c和c++，加密函数可以不用管，因为我试过不通过文本读而从中间量prt    printf("%s\n",prt);     printf("%d\n",strlen(prt));     AESDecode(prt, strlen(prt), &pcDecodeDst, &dstLen );     printf("%s\n",pcDecodeDst);     printf("%d\n",strlen(pcDecodeDst));     printf("\n");能解密成功！

user: user-0
content: #include <direct.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <QString> #include <QDir> #include "license.h"  void New_File(char *prt,char *prt1,int number);  int main(void) {     char buff[200], buff1[200], num[200];     char c = ';';     int n = 0, number, q = 0, m = 0;      FILE *fp = fopen("./KeyOutput.csv", "r+");     FILE *dp = fopen("./Nii.HwIdLic", "r+");     if(fp == NULL || dp ==NULL){         printf("ERROR:Open Fail!\n");         return 0;     }      while(fgets(buff, 200, fp))     {         if(m == 0){             m++;             continue;         }         strcpy(num,buff);          while(num[n]&&(num[n]<'0'|| num[n]>'9'))             n++;         if(num[n])         {             q = n+1;             number = num[n] - '0';             while(num[q]>='0'&&num[q]<='9')             {                 number = number*10+(num[q]-'0');                 q++;             }             n = 0;         }          char *prt = strrchr(buff,c);         prt += 1;         int cnum = strlen(prt);         char *pcEncodeDst = 0;         int dstLen = 0;         AESEncode(prt, cnum, &pcEncodeDst, &dstLen );          if(fgets(buff1, 200, dp))         {             char *prt1 = strchr(buff1,':');             prt1 += 1;             New_File(pcEncodeDst,prt1,number);         }     }       fclose(fp);     fclose(dp);     printf("Information:Conversion Success!\n");      return 0; }  void New_File(char *prt,char *prt1,int number) {     static int n = 0;     char fileName[200] = {0},buff[32];      QString dir_str = "./KeyTable";     QDir dir;     if (!dir.exists(dir_str))         dir.mkpath(dir_str);      strcpy(fileName, "./KeyTable/");     sprintf(fileName+11,"%d",number);     if(number<10)     {         strcat(fileName+4, "-A-");         sprintf(fileName+15,"%d",n);         strcat(fileName+4, ".nii");         FILE *fp1 = fopen(fileName, "w+");         if(fp1 == NULL){             printf("ERROR:Create Fail!");             return;         }         fwrite(prt,1,32,fp1);         fclose(fp1);          FILE *fp = fopen(fileName, "a+");         fputc('\r',fp);         fputc('\n',fp);         fwrite(prt1,1,84,fp);         n++;         fclose(fp);      }     else if(number>=10 && number<=99)     {         strcat(fileName+4, "-A-");         sprintf(fileName+16,"%d",n);         strcat(fileName+4, ".nii");         FILE *fp1 = fopen(fileName, "w+");         if(fp1 == NULL){             printf("ERROR:Create Fail!");             return;         }         fwrite(prt,1,32,fp1);         fclose(fp1);          FILE *fp = fopen(fileName, "a+");         fputc('\r',fp);         fputc('\n',fp);         fwrite(prt1,1,84,fp);         n++;         fclose(fp);     }     else if(number>=100 && number<=999)     {         strcat(fileName+4, "-A-");         sprintf(fileName+17,"%d",n);         strcat(fileName+4, ".nii");         FILE *fp1 = fopen(fileName, "w+");         if(fp1 == NULL){             printf("ERROR:Create Fail!");             return;         }         fwrite(prt,1,32,fp1);         fclose(fp1);          FILE *fp = fopen(fileName, "a+");         fputc('\r',fp);         fputc('\n',fp);         fwrite(prt1,1,84,fp);         n++;         fclose(fp);     }     else if(number>=1000 && number<=9999)     {         strcat(fileName+4, "-A-");         sprintf(fileName+18,"%d",n);         strcat(fileName+4, ".nii");         FILE *fp1 = fopen(fileName, "w+");         if(fp1 == NULL){             printf("ERROR:Create Fail!");             return;         }         fwrite(prt,1,32,fp1);         fclose(fp1);          FILE *fp = fopen(fileName, "a+");         fputc('\r',fp);         fputc('\n',fp);         fwrite(prt1,1,83,fp);         n++;         fclose(fp);     }      FILE *fp2 = fopen(fileName, "r");     fread(buff ,sizeof(buff),1,fp2);     printf("%s\n",buff);      fclose(fp2);  }

user: user-0
content: 饭否到 = 能否放