Mail Archives: djgpp/2000/12/16/16:11:47
From: | dontmailme AT iname DOT com (Steamer)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Cannot multiply
|
Date: | Sat, 16 Dec 2000 20:53:29 GMT
|
Organization: | always disorganized
|
Lines: | 58
|
Message-ID: | <3a3bd642.721644@news.freeserve.net>
|
References: | <000401c0679d$d5101020$ce3dfac1 AT franck>
|
NNTP-Posting-Host: | modem-88.clown-trigger.dialup.pol.co.uk
|
X-Trace: | newsg2.svr.pol.co.uk 977000010 14371 62.136.250.88 (16 Dec 2000 20:53:30 GMT)
|
NNTP-Posting-Date: | 16 Dec 2000 20:53:30 GMT
|
X-Complaints-To: | abuse AT theplanet DOT net
|
X-Newsreader: | Forte Free Agent 1.11/32.235
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Franck Bauquier (Defcon1) wrote:
> This is a multi-part message in MIME format.
Please don't post in HTML.
> I got a program which is supposed to fill SRC with 5 "ABCDEFGHIJ" in a =
> row. Then the program is gonna pick 1 letter from SRC every ten letters =
> and put
> it in DEST, thus DEST would be filled with "AAAAA".
> Unfortunately, although it's working under Turbo C++, DJGPP refuse to =
> compile
> apparently because of a multiplication at the line: "src[i*10]";
>
> Here's my source code:
It works for me (assuming =3D was meant to be = throughout).
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
>
> void main()
This should be
int main()
of course.
> {
> int i;
> char *src =3D (char *)malloc(100);
> char *dest =3D (char *)malloc(20);
You should always check that malloc() succeeds.
> strcpy(src,"ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ");
>
> for (i=3D0; i<5; i++) dest[i] =3D src[i*10]; /* ERROR */
What makes you think this line was causing problems?
> dest[5]=3D0;
>
> printf("\r\nSrc says: %s \r\nDest says: %s\n", src, dest);
You don't need \r with printf(). It works in text mode,
so \n gets translated to \r\n in DOS anyway.
> free(src);
> free(dest);
return 0;
(Not actually required according to the new C standard, but...)
> }
- Raw text -