Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!chaph.usc.edu!alcor.usc.edu!jeenglis From: jeenglis@alcor.usc.edu (Joe English) Newsgroups: comp.lang.c Subject: Re: NOT Educating FORTRAN programmers to use C Message-ID: <7536@chaph.usc.edu> Date: 21 Jan 90 03:00:17 GMT References: <649@chem.ucsd.EDU> <14191@lambda.UUCP> <12974@cbnewsc.ATT.COM> Sender: news@chaph.usc.edu Distribution: na Organization: University of Southern California, Los Angeles, CA Lines: 45 levy@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@nunki.usc.edu