我有一些问题。如果我手动输入文件路径,函数 fopen_s 总是失败,但如果我通过代码设置相同的路径,文件打开没有问题。我的第二个问题是“delete[] bytes”和“delete[] locatie”无法编译,我明白了
错误 C2065:“删除”未声明的标识符
和
C2059: 语法错误 ']'
我不知道为什么。ASM 部分是一个优化的循环顺便说一句。
char* getline()
{
char line[50];
char *eof;
line[0] = '\0';
line[sizeof(line)-1] = ~'\0';
eof = fgets(line, sizeof(line), stdin);
}
int _tmain(int argc, _TCHAR* argv[])
{
char* locatie, *bytes, c;
FILE* bestand;
int i, size;
struct stat st;
printf_s("Voer het pad van het bestand in en druk op enter.\n");
locatie = getline();
locatie[strlen(locatie)-1] ='\0';
locatie = "C:\\Users\\xxx\\Documents\\haha.txt"; // <-- this line
if ((i = fopen_s(&bestand, locatie, "r" )) != 0)
{
printf_s("Het bestand bestaat niet, of kon niet worden geopend!");
getchar();
return -1;
}
stat(locatie, &st);
size = st.st_size;
bytes = (char*)malloc(i+1);
i = 0;
loop:
c = fgetc(bestand);
__asm
{
movsx eax, byte ptr [c]
cmp eax, 0x0FFFFFFFF
je Break
mov eax, dword ptr [bytes]
add eax, dword ptr [i]
mov cl, byte ptr [c]
xor cl, 32
mov byte ptr [eax], cl
mov eax, dword ptr [i]
add eax, 1
mov dword ptr [i], eax
jmp loop
}
Break:
fclose(bestand);
bytes[i] = '\0';
printf(bytes);
locatie = "C:\\Users\\xxx\\Documents\\haha.cpt";
fopen_s(&bestand, locatie, "w");
fprintf_s(bestand, "%c", bytes);
fclose(bestand);
delete[] bytes;
delete[] locatie;
return 0;
}