| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
| From: | lando <landolini AT yahoo DOT com> |
| User-Agent: | Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.5) Gecko/20031007 |
| X-Accept-Language: | en-us, en |
| MIME-Version: | 1.0 |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | gcc |
| Lines: | 80 |
| Message-ID: | <fAVMb.107068$_P.3932301@news4.tin.it> |
| Date: | Tue, 13 Jan 2004 17:06:19 GMT |
| NNTP-Posting-Host: | 80.180.169.215 |
| X-Complaints-To: | newsmaster AT tin DOT it |
| X-Trace: | news4.tin.it 1074013579 80.180.169.215 (Tue, 13 Jan 2004 18:06:19 MET) |
| NNTP-Posting-Date: | Tue, 13 Jan 2004 18:06:19 MET |
| Organization: | TIN |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
This program (copied from "The C programming language" by Kernigham/
Ritchie)
doesn't work fine.
The operator enters some strings of characters and at EOF the program has to
display the longest string typed.........and this doesn't happen.
Where is the problem ?Thanks a lot.
#include <stdio.h>
#define MAXLINE 100
int max;
char line[MAXLINE];
char longest[MAXLINE];
int getline(void);
void copy(void);
main()
{
int len;
extern int max;
extern char longest[MAXLINE];
max=0;
while ((len=getline()) > 0)
if (len > max)
{
max = len;
copy();
}
if (max > 0)
printf("%s",longest,'\n');
return 0;
}
int getline(void)
{
int c,i;
extern char line[];
for (i=0;i<MAXLINE-1 && (c=getchar()) !=EOF && c !='\n';++i)
line[i] = c;
if (c=='\n')
{
line[i] = c;
++i;
}
line[i]='\0';
return i;
}
void copy(void)
{
int i;
extern char line[];
extern char longest[];
i=0;
while ((longest[i] = line[i]) !='\0')
++i;
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |