From: ams AT ludd DOT luth DOT se (Martin Str|mberg) Newsgroups: comp.os.msdos.djgpp Subject: Re: reusing string variables Date: 10 Jan 1999 14:34:57 GMT Organization: University of Lulea, Sweden Lines: 93 Message-ID: <77adqh$sl1$1@news.luth.se> References: <3697AD5C DOT C9493E2E AT iocc DOT com> <778dup$65j$1 AT news DOT luth DOT se> <3697BB38 DOT 87B2F2D1 AT iocc DOT com> <778lf3$90j$1 AT news DOT luth DOT se> <3698A560 DOT E2215062 AT iocc DOT com> NNTP-Posting-Host: queeg.ludd.luth.se X-Newsreader: TIN [UNIX 1.3 950824BETA PL0] To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Non vital information in (). vern (vern AT iocc DOT com) wrote: : here is the finction. it is the part of a 'scrolling window' that : displays the messages, and scrolls them. : the locate(x, y) function moves the cursor on the screen to column x, : and row y. the clrreset() function resets the text colors. : : : void msginput(char *msg) /* NEEDS WORK */ : { : : int x = 0; /* used as a loop counter */ : char msg1[78]; /* always contains line 1 */ : char msg2[78]; /* always contains line 2 */ : char msg3[78]; /* always contains line 3 */ : char msg4[78]; /* always contains line 4 */ Are these msg? supposed to remember things in between calls? The code later on seems to indicate that. Then you need to make them static. : textcolor(3); /* set color to cyan */ : : if(count==0) /* print on the top line */ : { : strcpy(msg1,msg); (As you know the max length is 78 I'd do this to guard against too long input strings: #define MAX_LEN (78) char msg1[ MAX_LEN ]; ... strncopy(msg1, msg, MAX_LEN); msg1[ MAX_LEN - 1 ] = 0; ) : locate(2,19); : cprintf("%s",msg1); : locate(2,20); : count++; : } : else if(count==1) /* print on the second line */ : { : strcpy(msg2,msg); : locate(2,20); : cprintf("%s",msg2); : locate(2,21); : count++; : } : else if(count==2) /* print on the third line */ : { : strcpy(msg3,msg); : locate(2,21); : cprintf("%s",msg3); : locate(2,22); : count++; : } : else if(count==3) /* print on the fourth line */ : { : strcpy(msg4,msg); : locate(2,22); : cprintf("%s",msg4); : count++; : } : else if(count==4) /* move everything up a line, and print the newest : line */ (Perhaps you should consider a switch statement.) : { : strcpy(msg1,msg2); /* recopy all the strings */ : strcpy(msg2,msg3); : strcpy(msg3,msg4); : strcpy(msg4,msg); Here you copy garbage to msg1, then garbage to msg2, then to msg3. Then you copy your in param (msg) to msg4. : locate(2,19); : : cprintf(" : "); (What's this? Doesn't cprintf() support '\n'?) [Klippa, klapp, kluppit rest of code.] Holmboe, Symphony No. 8, MartinS