Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!tank!shamash!com50!dayton!joe From: joe@dayton.UUCP (Joseph P. Larson) Newsgroups: comp.sys.amiga Subject: Re: Struggling through the "C" Message-ID: <6480@dayton.UUCP> Date: 1 Apr 89 16:22:01 GMT References: <12000@louie.udel.EDU> <97113@sun.Eng.Sun.COM> Reply-To: joe@dayton.UUCP (Joseph P. Larson) Organization: Dayton-Hudson Dept. Store Co. Lines: 33 In article <97113@sun.Eng.Sun.COM> cmcmanis@sun.UUCP (Chuck McManis) writes: >In article <12000@louie.udel.EDU> (Rob Lizak Jr.) writes: >> FOR I=1 TO LEN(A$) >> PRINT MID$(A$,I,1); >> NEXT I > >C equivalent might be more syntactically written as > for (i=0; i < strlen(a); i++) > printf("%c", a[i]); Oh, but people... Don't use Chuck's code. It appears very straightforward, except that you can't convince C not to execute the strlen() every time. Yes, boys and girls -- Chuck's code will execute strlen(a) strlen(a)+1 times. So what you might want to do is: for (i = 0, count = strlen(a); i < count; i++) printf("%c", a[i]); Now, I realize most people out there KNOW C is going to do this to them, but as long as we're giving C lessons to begin with, we might as well make sure the novices are aware that C executes all parts of the conditional in a for-loop exactly one more time than the number of iterations through the loop. (The test is at the top of the loop, so it checks once for each loop plus takes the time that the condition fails.) Of course, printf("%s", a) will work, too, but that's beside the point. -Joe -- Life is a cabaret (old chum). UUCP: rutgers!dayton!joe (Picts 1-13 are DHDSC - Joe Larson/MIS 1060 ATT : (612) 375-3537 now ready.) 700 on the Mall, Mpls, Mn. 55402