处理一些需要在函数中使用unsigned char的加密,但希望在解密后转换为char以供使用.所以我有:
unsigned char plaintext[16];
char *plainchar;
int plainint;
... Code now populates plaintext with data that happens to all be plain text
Run Code Online (Sandbox Code Playgroud)
现在在这一点上,让我们说明文实际上是一个"0123456789"的数据字符串.如何将明文的值作为"012456789"获取为plainchar,同时将plainint作为123456789?
- 编辑 -
当明文等于"AAAAAAAAAA105450"时执行此操作:
unsigned char plaintext[16];
char *plainchar;
int plainint;
... Code now populates plaintext with data that happens to all be plain text
plainchar = (char*)plaintext;
Run Code Online (Sandbox Code Playgroud)
使plainchar等于"AAAAAAAAAA105450╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠┤∙7",sizeof = 51.加密代码是rijndael示例代码,所以它应该工作正常.
谢谢,本
试图弄清楚如何使用C和C++文件来编译应用程序.不是整个代码,但足以得到这个想法:
main.cpp中:
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "one.h"
#include "two.h"
int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hInst2, LPSTR lpCmdLine, int nShowCmd) {
FunctionOne();
FunctionTwo();
}
Run Code Online (Sandbox Code Playgroud)
one.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <gdiplus.h>
#include <gdiplusflat.h>
using namespace Gdiplus;
using namespace Gdiplus::DllExports;
int FunctionOne() {
}
Run Code Online (Sandbox Code Playgroud)
two.c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int FunctionTwo() {
}
Run Code Online (Sandbox Code Playgroud)
头文件仅包含这些函数的定义.
现在,如果我使用main.cpp编译它,我会得到一个FunctionTwo的"未解析的外部符号".如果我使用main.c编译它,我会得到与FunctionOne相同的东西.这是否可能,如果是这样,我如何设置项目以便正确编译(Visual Studio 2010)?
如果我根据main的扩展名注释掉备用函数,它编译得很好.
谢谢!
下面是一些psudo,但我正在努力实现这一目标.问题是写的,它返回一个空白指针.
int testFunction(char *t) {
int size = 100;
t = malloc(100 + 1);
t = <do a bunch of stuff to assign a value>;
return size;
}
int runIt() {
char *str = 0;
int str_size = 0;
str_size = testFunction(str);
<at this point, str is blank and unmodified, what's wrong?>
free(str);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我有一个预定义的大小,例如char str [100] =""并且我不尝试malloc或释放内存后记录,这可以正常工作.我需要能够使尺寸变得动态.
我也试过这个,但似乎不知何故遇到了一个腐败的指针.
int testFunction(char **t) {
int size = 100;
t = malloc(100 + 1);
t = <do a …Run Code Online (Sandbox Code Playgroud)