NOT Educating FORTRAN programmers to use C
    Joe English 
    jeenglis at alcor.usc.edu
       
    Sun Jan 21 14:00:17 AEST 1990
    
    
  
levy at cbnewsc.ATT.COM (Daniel R. Levy) writes:
>C
>C  FORTRAN77 code to read two lines (assumed 80-characters wide, max),
>C  put their concatention in a buffer,
>C  then print the concatenation between double quotes
>C
[ 35 lines deleted ]
>Ugh.  Now let's try that in C...
>
[ 15 lines deleted ]
Well, some might say that using sprintf() to 
do the concatenation is cheating, so let's do
it "by hand:"
    char *src,*dst;
    int remaining;
    dst = str3;
    remaining = BUFLEN;
    src = str1;
    while (*src && remaining) {
        *dst++ = *src++;
        remaining--;
    }
    src = str2;
    while (*src && remaining)  {
        *dst++ = *src++;
        remaining--;
    }
    *dst = '\0';
The C implementation is still shorter, but more
importantly it's a lot clearer (to me, anyway.) It
also looks more "efficient" than the Fortran version,
but I'll leave that for Jim Giles to decide since he's
the one who knows what the optimizer can and can't do.
--Joe English
  jeenglis at nunki.usc.edu
    
    
More information about the Comp.lang.c
mailing list