int i = 0; int numwrite = 0; int numread = 0; int file_len = 30; char file[30] = {'0'}; FILE *fp;if ( ( fp = fopen("filename.txt","r") ) == NULL) { printf("Can't open the filename file!"); } else { long file_seek = 0; for(i = 0; i < file_len; i++) { int position = ftell(fp); int result = fseek(fp,file_seek,SEEK_SET); if (result) { printf("fseek file failed!"); } numread = fread( file, sizeof( char ), 25, fp ); position = ftell(fp); char *str = file; i = 0; while(*str != '\0') { //*str to Binary //Binary to store into b mode file str++; } file_seek += 25; } } fclose(fp);
可以用 sprintf() 可以设置参数为二进制,然后把这个字符串存盘 这应该是最方便的办法了
pszString [in] Pointer to the formatted string to be converted. cchString [in] Number of characters of the formatted string to be converted. If pszString is NULL-terminated, cchString can be zero. The length of pszString is calculated including the NULL terminator. dwFlags [in] Indicates the format of the string to be converted. The following table gives details. Flag Format of the string to be converted CRYPT_STRING_BASE64HEADER Base64, with certificate beginning and ending headers CRYPT_STRING_BASE64 Base64, without headers CRYPT_STRING_BINARY Pure binary copy CRYPT_STRING_BASE64REQUESTHEADER Base64, with request beginning and ending headers CRYPT_STRING_HEX Hex only format CRYPT_STRING_HEXASCII Hex format with ASCII char display CRYPT_STRING_BASE64X509CRLHEADER Base64, with x509 CRL beginning and ending headers CRYPT_STRING_HEXADDR Hex, with address display CRYPT_STRING_HEXASCIIADDR Hex, with ASCII char and address display CRYPT_STRING_BASE64_ANY Tries the following, in order: CRYPT_STRING_BASE64HEADER CRYPT_STRING_BASE64
CRYPT_STRING_ANY Tries the following, in order: CRYPT_STRING_BASE64_ANY CRYPT_STRING_BINARY
CRYPT_STRING_HEX_ANY Tries the following, in order: CRYPT_STRING_HEXADDR CRYPT_STRING_HEXASCIIADDR CRYPT_STRING_HEXASCII CRYPT_STRING_HEX
pbBinary [in] Pointer to a buffer to hold the returned sequence of bytes. If it is set to NULL, the function calculates the length of the buffer needed for the return sequence and returns the size of required memory for the DWORD pointed to by pcbBinary. pcbBinary [in, out] Length of the returned binary sequence. If the value of *pcbBinary passed in is not big enough, the function fails with GetLastError returning ERROR_MORE_DATA. pdwSkip [out] Count of characters in any skipped strings up to the beginning of actual base64 or hex strings. pdwFlags [out] Actual format used in the conversion.
二进制文件----0100101
LPCWSTR pszString,
DWORD cchString,
DWORD dwFlags,
BYTE *pbBinary,
DWORD *pcbBinary,
DWORD *pdwSkip,
DWORD *pdwFlags
);
fwrire是一致的fopen("1.txt", "b");//二进制
fopen("1.txt", "t");//文本
int numwrite = 0;
int numread = 0;
int file_len = 30;
char file[30] = {'0'};
FILE *fp;if ( ( fp = fopen("filename.txt","r") ) == NULL)
{
printf("Can't open the filename file!");
}
else
{
long file_seek = 0;
for(i = 0; i < file_len; i++)
{
int position = ftell(fp);
int result = fseek(fp,file_seek,SEEK_SET);
if (result)
{
printf("fseek file failed!");
}
numread = fread( file, sizeof( char ), 25, fp );
position = ftell(fp);
char *str = file;
i = 0;
while(*str != '\0')
{
//*str to Binary
//Binary to store into b mode file
str++;
}
file_seek += 25;
}
}
fclose(fp);
可以设置参数为二进制,然后把这个字符串存盘
这应该是最方便的办法了
[in] Pointer to the formatted string to be converted.
cchString
[in] Number of characters of the formatted string to be converted. If pszString is NULL-terminated, cchString can be zero. The length of pszString is calculated including the NULL terminator.
dwFlags
[in] Indicates the format of the string to be converted. The following table gives details. Flag Format of the string to be converted
CRYPT_STRING_BASE64HEADER Base64, with certificate beginning and ending headers
CRYPT_STRING_BASE64 Base64, without headers
CRYPT_STRING_BINARY Pure binary copy
CRYPT_STRING_BASE64REQUESTHEADER Base64, with request beginning and ending headers
CRYPT_STRING_HEX Hex only format
CRYPT_STRING_HEXASCII Hex format with ASCII char display
CRYPT_STRING_BASE64X509CRLHEADER Base64, with x509 CRL beginning and ending headers
CRYPT_STRING_HEXADDR Hex, with address display
CRYPT_STRING_HEXASCIIADDR Hex, with ASCII char and address display
CRYPT_STRING_BASE64_ANY Tries the following, in order:
CRYPT_STRING_BASE64HEADER
CRYPT_STRING_BASE64
CRYPT_STRING_ANY Tries the following, in order:
CRYPT_STRING_BASE64_ANY
CRYPT_STRING_BINARY
CRYPT_STRING_HEX_ANY Tries the following, in order:
CRYPT_STRING_HEXADDR
CRYPT_STRING_HEXASCIIADDR
CRYPT_STRING_HEXASCII
CRYPT_STRING_HEX
pbBinary
[in] Pointer to a buffer to hold the returned sequence of bytes. If it is set to NULL, the function calculates the length of the buffer needed for the return sequence and returns the size of required memory for the DWORD pointed to by pcbBinary.
pcbBinary
[in, out] Length of the returned binary sequence. If the value of *pcbBinary passed in is not big enough, the function fails with GetLastError returning ERROR_MORE_DATA.
pdwSkip
[out] Count of characters in any skipped strings up to the beginning of actual base64 or hex strings.
pdwFlags
[out] Actual format used in the conversion.