我想製作一個程序來分析.exe
文件的命令,並對內容做出一些決定。問題在這裏:我從我的程序文件夾(它也使用C)中的C項目複製了.exe
。我改變了它的擴展名從.exe
到.txt
並提出這樣的代碼:在程序後面獲取代碼
#include <stdio.h>
#include <stdlib.h>
int apare(char a, char s[]) //this function search a character in a string.
{
printf("merge");
int nr=strlen(s),i;
for(i=0; i<nr; i++)
{
if(a==s[i])
return 1;
}
return 0;
}
int main()
{
FILE * f=fopen("program in C.txt","r");
char c,s[10000]="abcedfghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ _-+=.,<>[email protected]#$%^&*()1234567890{}[];:'";//The characters I want to be printed
int a=1,k=0;//k is only used to printf "\n" when 1100 characters have been displayed on a line
while(a)
{
c=fgetc(f);//A char is read
if(c!=EOF)//If no error occurs than display the character if it is present in the string.
{
if(apare(c,s))
{
printf("%c",c);
k++;
}
}
else if(ferror) //If an error occurs than read the next char
c=fgetc(f);
else //If EOF than stop reading
a=0;
if(k==100)
{
k=0;
printf("\n");
}
}
return 0;
}
我的問題是,這個程序顯示「怪」字了。這個程序的作用是隻獲取可讀部分。爲什麼會發生?
@iharob :)看到'INT apare(CHAR一,個char [])...' –
你可以格式化你這樣的代碼,人類可以也讀它。 –
也許你可以考慮使用'isprint()'來檢查可打印的字符... –