Do you have a question? Post it now! No Registration Necessary
February 14, 2007, 6:39 am

Hi,
I tried to compare same file on linux. for this i did
while(read(fd1, ptr1, 1) || read(fd2, ptr2, 1)) {
....
....
....
}
but in this case only first read works. some one told me compiler is
doing optimization then I compiled it with -O0 option but even then
its giving same result. Can any one tell me why so . and what option
should I give to compile so that I can read both the file in same
whilel
Regards
Sumit Shrivastava
I tried to compare same file on linux. for this i did
while(read(fd1, ptr1, 1) || read(fd2, ptr2, 1)) {
....
....
....
}
but in this case only first read works. some one told me compiler is
doing optimization then I compiled it with -O0 option but even then
its giving same result. Can any one tell me why so . and what option
should I give to compile so that I can read both the file in same
whilel
Regards
Sumit Shrivastava

Re: tried to compace same file

You are either joking, or in desperate need of "Intro to C
Programming".

Someone either didn't see your code, or is just as clueless as
you are.

As it should.

Because the C language standard requires it be so.

A magical option to fix buggy program. You wish.
Read about short-circuit evaluation here:
http://en.wikipedia.org/wiki/Short-circuit_evaluation
Then fix your bug(s).
Also note that read()ing files one byte at a time is extremely
inefficient. Better read larger chunks, and memcmp()are them.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

Re: tried to compace same file
different it should be printed with line no. I first tried with same
file only. How can I use memcmp or some other API . I am not getting
please tell me
Regards
Sumit Shrivastava
wrote:


Re: tried to compace same file

That code segment is not comparing anything. Probably you meant to
write
while(read(fd1, ptr1, 1) == read(fd2, ptr2, 1)) { ... }
As mentioned in another reply, this is a very inefficient way to
compare two files, but may be acceptable if the files are small.
Roberto Waltman
[ Please reply to the group,
return address is invalid ]

Re: tried to compace same file
| Hi,
| I tried to compare same file on linux. for this i did
| while(read(fd1, ptr1, 1) || read(fd2, ptr2, 1)) {
This logic says: try to read from fd1 and if that fails then try to
read from fd2. As long as reading from fd1 succeeds, reading from
fd2 will not be tried. In a loop it will repeat reading from fd1
until EOF makes it fail, then it will repeat trying fd1 over and over
and reading from fd2 on each of those failures.
You need to read both files then you need to compare the contents of
the buffers after reading.
--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
We've slightly trimmed the long signature. Click to see the full one.
Site Timeline
- » test--20070214.1104
- — Next thread in » Embedded Linux
-
- » Initial Console Problem
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Corona Death Star comic strip
- — The site's Newest Thread. Posted in » Electronics Design
-
- » Sheesh
- — The site's Last Updated Thread. Posted in » Electronics Repair
-