This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem with sizeof

hi
i wrote this code which is written bellow when ever i check the value of u it appear to be the 3. while it is supposed to be 8.
Can any body tell me what is the problem with this code and how can i get the exact size of the arrgument of func.

void main(){
  func("fara.txt");
}
void func(unsigned char arr[]){
int u;
u=sizeof(arr);
}
thanks
Regards
Farhan Arshad

Parents
  •     int u,v;
        u = sizeof( "Hello World\n" );
        v = strlen( "Hello World\n" ); 
    It is left as another excercise for the student to explain why u and v receive different values in the above example...

    Anyhow, as Jon says, if you want the length of a string, then use strlen - that's what it's there for!

Reply
  •     int u,v;
        u = sizeof( "Hello World\n" );
        v = strlen( "Hello World\n" ); 
    It is left as another excercise for the student to explain why u and v receive different values in the above example...

    Anyhow, as Jon says, if you want the length of a string, then use strlen - that's what it's there for!

Children