View Single Post
  #1 (permalink)  
Old March 6th, 2008, 12:05 AM
manih manih is offline
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can someone help me

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>


int main(int argc, char **argv)
{
    int i;

    struct stat *buf;

    for (i = 1; i < argc; i++)
    {
        if (stat(*(argv + i), buf) == -1)
        {
            fprintf(stderr, "%s: cannot access %s\n", *(argv), *(argv + i));
            continue;
        }
        printf("Hello\n");
    }
}

Hi
Can someone help me whats wrong with my code on line 14 if(stat() == -1)? my code compiles fine on gcc, but when i run my code, i get segmentation fault (core dumped).

my code works fine when i use char *argv[], but not with doube pointer.


Thanks
Regards
Mani

Reply With Quote