Segmentation fault on writing char to char* address

Posted by Lukas Dojcak on Stack Overflow See other posts from Stack Overflow or by Lukas Dojcak
Published on 2010-06-15T10:42:32Z Indexed on 2010/06/15 10:42 UTC
Read the original article Hit count: 317

Filed under:
|
|
|

hi guys,

i've got problem with my little C program. Maybe you could help me.

char* shiftujVzorku(char* text, char* pattern, int offset){
char* pom = text;
int size = 0;
int index = 0;
while(*(text + size) != '\0'){
    size++;
}
while(*(pom + index) != '\0'){
    if(overVzorku(pom + index, pattern)){
        while(*pattern != '\0'){
            //vyment *pom s *pom + offset
            if(pom + index + offset < text + size){
                char x = *(pom + index + offset);
                char y = *(pom + index);
                int adresa = *(pom + index + offset);
                *(pom + index + offset) = y;   <<<<<< SEGMENTATION FAULT
                *(pom + index) = x;   
                //*pom  = *pom - *(pom + offset);
                //*(pom + offset) = *(pom + offset) + *pom;
                //*pom = *(pom + offset) - *pom;
            }
            else{
                *pom  = *pom - *(pom + offset - size);
                *(pom + offset - size) = *(pom + offset - size) + *pom;
                *pom = *(pom + offset - size) - *pom;
            }
            pattern++;
        }
        break;
    }
    index++;
}
return text;

}

Isn't important what's the programm doing. Mayby there's lot of bugs. But, why do I get SEGMENTATION FAULT (for destination see code) at this line? I'm, trying to write some char value to memory space, with help of address "pom + offset + index". Thanks for everything helpful. :)

© Stack Overflow or respective owner

Related posts about c++

Related posts about c