0
私は0xbfe0e6ac
のようなポインタ数値を受け取ることができます。例えば、の値をメモリ内の別のintに設定すると、int foo
を設定できますか?RAM上のインデックスによって変数値を設定するにはどうすればよいですか?
私scenare:
Iは、パラメータとして(上記の例のような)ポインタ値を渡す配列から次のインデックスを取得するための機能を実装しようとしたのです。例えば
:
char * a = "baa";
char* b = "foo";
printf("%c", cgetnext(&a)); // b
printf("%c", cgetnext(&a)); // a
printf("%c", cgetnext(&b)); // f
printf("%c", cgetnext(&b)); // a
私はこれを行うには見ることができ、単一の方法がある:cgetnex()
で、配列にパラメータと各呼び出しのように渡された配列のポインタを保存するチェックのparamaterとして渡された配列を使用した場合その前にlasindexusedやRAMへのポインタ値などの情報を取得します。私はこれがあなたのために明らかであると思います
#include <string.h>
#include <stdlib.h>
typedef struct { int pLocation; int lastIndex; } POINTERINFORMATION;
int __myIndex;
POINTERINFORMATION pointersLocations[256];
int pointersLocationsLength;
char * temparr = NULL;
__myIndex = pointersLocationsLength = 0;
int
plAdd (int p)
{
if (plLen >= sizeof(pointersLocation)) {
return -1;
} else {
pointersLocation[pointersLocationsLength].pLocation = p;
pointersLocation[pointersLocationsLength].lastindex = 0;
pointersLocationsLength ++;
return pointersLocationsLength;
}
}
int
getPointer (int p, POINTERINFORMATION ** out)
{
int i;
for (i = 0; i < pointersLocationsLength; i++)
{
if(pointersLocation[pointersLocationsLength].pLocation == p)
{
*out = makevariablefromponiter(pi.pLocation);
return 1;
}
}
return 0;
}
char
cgetnext(char * arr)
{
char * myarr;
const size_t size = sizeof(char *) + 1;
myarr = malloc(size);
if (NULL == arr){
POINTERINFORMATION * pi;
if (getPointer(p, &pi))
{
__myIndex = pi.lastindex;
myarr = makevariablefromponiter(pi.pLocation);
}
} else {
myarr = strdup (arr);
}
if (strlen(myarr) == __myIndex) {
return '\0';
} else {
__myIndex ++;
temparr = malloc(size);
temparr = strdup(myarr);
return myarr[__myIndex - 1];
}
}
: はここに私のコードです。任意のヘルプは非常に高く評価されます。前もって感謝します。
OWを、どうもありがとう! :) – Jack
別の質問:ポインタのインデックス値を保存するための 'int'十分なものか' long'を使うべきですか? – Jack
@Jack 'int'は十分な大きさでなければなりません –