Janis Papanagnou
6/9/2011 9:11:00 AM
Am 09.06.2011 10:57, schrieb Uno:
> On 06/08/2011 10:20 PM, Uno wrote:
>> On 06/08/2011 10:08 PM, Ian Collins wrote:
>>> On 06/ 9/11 03:59 PM, Uno wrote:
>>>>
>>>> I want to pursue this on the C side for a bit. [x-posted to clc]
>>>>
>>>> $ pwd
>>>> /home/dan/source/bdiff-1.0
>>>> $ cc -Wall -Wextra cmp1.c -o cmp
>>>> cmp1.c: In function â??mainâ??:
>>>> cmp1.c:12: warning: comparison is always true due to limited range of
>>>> data type
>>>> cmp1.c:17: warning: implicit declaration of function â??closeâ??
>>>> cmp1.c:18: error: expected declaration or statement at end of input
>>>> $ cat cmp1.c
>>>>
>>>> #include<stdio.h>
>>>>
>>>> int main(void)
>>>> {
>>>> unsigned char c;
>>>> long counter = 0;
>>>> FILE *fp;
>>>>
>>>> fp=fopen("shoulder.wmv", "rb+");
>>>>
>>>> while ((c = fgetc(fp)) != EOF)
>>>
>>> I'm guessing this is line 12. fgetc returns an int. EOF is an integer
>>> constant.
>>>
>>>> {
>>>> counter++;
>>>> }
>>>> printf("Counter reached %ld\n", counter);
>>>> close (fp);
>>>
>>> You are missing <unistd.h>. If you had included it, your compile would
>>> have failed. close works with a file descriptor, not a FILE*.
>>>
>>>> return 0;
>>>
>>> Missing } ?
>>>
>>
>> Thx, Ian.
>>
>> $ cc -Wall -Wextra cmp2.c -o cmp
>> $ ./cmp
>> Counter reached 19573712
>> $ ls -l
>> ...
>> -rw-r--r-- 1 dan dan 19573712 2011-06-05 17:32 shoulder.wmv
>> $ cat cmp2.c
>>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>> int c;
>> long counter = 0;
>> FILE *fp;
>>
>> fp=fopen("shoulder.wmv", "rb+");
>>
>> while ((c = fgetc(fp)) != EOF)
>> {
>> counter++;
>> }
>> printf("Counter reached %ld\n", counter);
>> fclose (fp);
>> return 0;
>> }
>> // cc -Wall -Wextra cmp2.c -o cmp
>> $
>>
>> I guess I thought with counter starting at zero that the numbers
>> wouldn't agree exactly, but they do.
>>
>> It's a weird night here in abq; I'm gonna go out and howl at the orange
>> moon.
>
> I'm stuck again, so that's the night. I don't see why this wouldn't
> traverse both files for the length of the shorter one:
Here you seem to be asking why your algorithm doesn't work,
but below you show us an apparent compiler syntax error;
your parenthesis are not balanced in line 12.
>
> $ cc -Wall -Wextra cmp4.c -o cmp
> cmp4.c: In function â??mainâ??:
> cmp4.c:12: error: expected statement before â??)â?? token
> $ cat cmp4.c
> #include <stdio.h>
>
> int main(void)
> {
> int c, d;
> long counter = 0;
> FILE *fp, *fq;
>
> fp=fopen("shoulder.wmv", "rb+");
> fq=fopen("downloaded1.wmv", "rb+");
>
> while (((c = fgetc(fp)) != EOF) || (d = fgetc(fq)) != EOF))
while ( (c = fgetc(fp)) != EOF
|| (d = fgetc(fq)) != EOF )
> {
> counter++;
> if (counter == 10000)
> {
> printf("int is %d\n", c);
> }
>
> if ( c != d)
> {
> printf("Ungleich: %ld\n", counter);
> }
> }
> printf("Counter reached %ld\n", counter);
> fclose (fp);
> return 0;
> }
> // cc -Wall -Wextra cmp4.c -o cmp
> $
>
> My parens are probably mismatched by now, but I don't make one statement
> on that line; I think I make two.
The compiler doesn't know what your intention was; it's irrelevant
how many statements you have. Fix your syntax.
BTW, why are you posting this to comp.unix.shell?
Janis