can any one tell me what's wrong with this program?
#include<sys/stat.h>
#include<fcntl.h>
Firstly, some missing headers (unistd.h and stdio.h).
Secondly, this should give you some hints of where to look for problems:
$ valgrind ./a >/dev/null
==14808== Memcheck, a memory error detector.
==14808== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et
al.
==14808== Using LibVEX rev 1804, a library for dynamic binary
translation.
==14808== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==14808== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation
framework.
==14808== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et
al.
==14808== For more details, rerun with: -v
==14808==
==14811== Syscall param open(mode) contains uninitialised byte(s)
==14811== at 0x40007F2: (within /lib/ld-2.7.so)
==14811== by 0x405F44F: (below main) (in /lib/i686/cmov/libc-2.7.so)
OPEN OPERATION: Inappropriate ioctl for device
WRITE OPERATION: Illegal seek
FSYNC OPERATION: Illegal seek
==14811==
==14811== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 11 from
1)
==14811== malloc/free: in use at exit: 0 bytes in 0 blocks.
==14811== malloc/free: 3 allocs, 3 frees, 1,056 bytes allocated.
==14811== For counts of detected errors, rerun with: -v
==14811== All heap blocks were freed -- no leaks are possible.
OPEN OPERATION: Permission denied
==14808== Syscall param read(buf) contains uninitialised byte(s)
==14808== at 0x40007F2: (within /lib/ld-2.7.so)
==14808== by 0x405F44F: (below main) (in /lib/i686/cmov/libc-2.7.so)
==14808== Warning: invalid file descriptor -1 in syscall read()
READ OPERATION: Bad file descriptor
==14808== Warning: invalid file descriptor -1 in syscall close()
==14808==
==14808== Conditional jump or move depends on uninitialised value(s)
==14808== at 0x4087B0E: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Use of uninitialised value of size 4
==14808== at 0x40239D8: strlen (mc_replace_strmem.c:242)
==14808== by 0x408A681: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Use of uninitialised value of size 4
==14808== at 0x40239E3: strlen (mc_replace_strmem.c:242)
==14808== by 0x408A681: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Conditional jump or move depends on uninitialised value(s)
==14808== at 0x40244B7: mempcpy (mc_replace_strmem.c:77)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Conditional jump or move depends on uninitialised value(s)
==14808== at 0x4024540: mempcpy (mc_replace_strmem.c:80)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Conditional jump or move depends on uninitialised value(s)
==14808== at 0x40244CE: mempcpy (mc_replace_strmem.c:676)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Conditional jump or move depends on uninitialised value(s)
==14808== at 0x402450E: mempcpy (mc_replace_strmem.c:676)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Conditional jump or move depends on uninitialised value(s)
==14808== at 0x4024556: mempcpy (mc_replace_strmem.c:676)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Use of uninitialised value of size 4
==14808== at 0x4024563: mempcpy (mc_replace_strmem.c:676)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== Use of uninitialised value of size 4
==14808== at 0x4024570: mempcpy (mc_replace_strmem.c:676)
==14808== by 0x40AE345: _IO_file_xsputn (in
/lib/i686/cmov/libc-2.7.so)
==14808== by 0x408A952: vfprintf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x40901D2: printf (in /lib/i686/cmov/libc-2.7.so)
==14808== by 0x8048680: main (a.c:30)
==14808==
==14808== ERROR SUMMARY: 254 errors from 11 contexts (suppressed: 11
from 1)
==14808== malloc/free: in use at exit: 0 bytes in 0 blocks.
==14808== malloc/free: 2 allocs, 2 frees, 704 bytes allocated.
==14808== For counts of detected errors, rerun with: -v
==14808== All heap blocks were freed -- no leaks are possible.