is my function correct?

Posted by sbsp on Stack Overflow See other posts from Stack Overflow or by sbsp
Published on 2010-03-24T18:23:36Z Indexed on 2010/03/24 18:33 UTC
Read the original article Hit count: 305

Filed under:
|
|

This is part of an assignment so please dont post solutions, just point me in the right direction if possible?

I am passing a pointer to a char array to my method, as well as a value for the actual height of the char array. I am looping through to see if all values are 0, if they are then return 0, esle return one

The method is used as a test to see if i should free memory or not and set the pointer to null if it is full of 0's. The issue i am having is that the programme should have "some unfree" memory at the end, so i have no idea whether or not its doing it correctly - and gdb i struggle with immensley.

Thanks for reading

int shouldBeNull(char *charPointer, int sizeOfCharArray)
{
    int isIn = 0;
    int i = 0;

    while(i < sizeOfCharArray){
        if(*charPointer != '0'){
            isIn = 1;
            break;
        }
        i++;
        charPointer++;
    }   
    return isIn;     
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointers