void OneDToTwoD(char* rel){
/* all the declarations here */
while(rel[i] != '\0'){
i++;
}
...
In the code above, I am getting all “sometimes” a segmentation fault. and valgrind check throws “Invalid read of size 1” at me at the line
while(rel[i] != '\0'){
In that line, I’m trying to figure out the length of rel.
I know there must be a better way to do this. I can’t just do sizeof can I?
If
iis initialized as zero, andrelis pointed to valid memory block, this will work well.relis pointed to invalid memory block or NULL.\0iis not started with 0.And one more answer, you can’t know the size of memory block from pointer. pointer is not memory block. pointer can specify invalid memory block if you want. So if you want to know the length of memory block, add the
lengthargument to the function.