0
我需要使用C來實現這個方法(https://en.wikipedia.org/wiki/Padding_%28cryptography%29#PKCS7),它沒有方便的功能來做到這一點。零填充:如何從文件結尾刪除零?
我加入這樣
int main()
{
FILE *file=fopen("1.xlsx", "a");
file_add(16,file);
fclose(file);
}
void file_add(int SizeOfBlock, FILE *file)
{
fseek(file, 0, SEEK_END);
int size = ftell(file); // file size in bytes
fseek(file, 0, SEEK_SET);
int diff = size%SizeOfBlock;
char arr[16] = "0000000000000000"; //16 zeroes
fwrite(arr, SizeOfBlock-diff, 1 , file); // here I added to end of file missing 0 to make size of file be dividing to SizeOfBlock
}
void file_remove (int SizeOfBlock, FILE *file)
{
// by this function I need to delete these zeroes
// max amount of zeroes is limited by SizeOfBlock
}
我怎麼能這樣做? SizeOfBlock
只能是8或16
'0'不是'\ 0'。 – BLUEPIXY
@Rocketq他意味着你的代碼將可打印的字符'0'(零,ascii值48)添加到文件的末尾,而不是實際的'NUL'字符。 –
你想寫0作爲填充數字字符? – BLUEPIXY