패턴을 비교하려고합니다. 그래서 문자열을 패턴을 보유하고 구조체가 있지만 문자열을 작성하고 해당 문자열 값을 구조체에 저장할 수 있기를 원합니다. 지금은 문자열의 주소 만 복사하고 있습니다. 당신이 문자열 "14"를 타고는 14의 값이 숫자가 될 수 있도록 할 말은 경우char *에서 문자열의 값을 얻는 방법 주소가 아님
typedef struct
{
int emp;
char *context;
int numOnes;
int numZeros;
}Pattern;
char *patt, str[t+1];
patt = str;
while(count<t){
//printf("Stream: %d\n", stream[end]);
if(stream[end] == 1){
patt[count]= '1';
//writeBit(1);
}
else{
patt[count]='0';
//writeBit(0);
}
end--;
count++;
}
patt[count]=0;//building string
if(found == 0){//if pattern doesnt exist, add it in
patterns[patternsIndex].context = patt; //NEED HELP HERE. This copies the address not the actual value, which is what i need
patterns[patternsIndex].emp = 1;
prediction = 0;
checkPredict(prediction,stream[end],patternsIndex);
patternsIndex++;
found =1;
}
'strcpy()'를 찾고있을 수 있습니다. 배열이 아닌 단지 포인터로 시작한다면 복사하기 전에 메모리를 할당해야합니다. 복사 할 수있는 유효한 메모리가있을 때까지 문자열을 복사 할 수 없기 때문입니다. –