Search code examples
cmemset

memset does not work (C)


char path[25500]= {};//iniatize
int visited[2500]= {0};//iniatialize
void fun();//protype

int main(){
    fun();
}

void fun(){
    visited[2300]=1;
    path[0]='9';
    printf("\n%d %s",visited[2300],path);
    memset(path,0,25500);//reset
    memset(visited,0,2500);//reset
    printf("\n %d %s",visited[2300],path);//to see if resetted
}

Outputs are:

1 9
1

I want to reset just like in the start. But as you can see, memset doesnot reset. My compiler is codeblocks.


Solution

  • memset(visited,0,2500);//reset
    

    Visited is an array of integers, so this should be

    memset(visited, 0, 2500 * sizeof(int))