Message-ID: <000401c0679d$d5101020$ce3dfac1@franck> From: "Franck Bauquier (Defcon1)" To: , Subject: Cannot multiply Date: Sat, 16 Dec 2000 21:18:59 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0005_01C067A5.CE54C2A0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C067A5.CE54C2A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi! 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: #include #include #include void main() { int i; char *src =3D (char *)malloc(100); char *dest =3D (char *)malloc(20); strcpy(src,"ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ"); for (i=3D0; i<5; i++) dest[i] =3D src[i*10]; /* ERROR */ dest[5]=3D0; printf("\r\nSrc says: %s \r\nDest says: %s\n", src, dest); free(src); free(dest); } ------=_NextPart_000_0005_01C067A5.CE54C2A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi!
 
I got a program which is supposed to = fill SRC with=20 5 "ABCDEFGHIJ" in a row. Then the program is gonna pick 1 letter from = SRC every=20 ten letters and put
it in DEST, thus DEST would be filled with=20 "AAAAA".
Unfortunately, although it's working under Turbo C++, DJGPP = refuse=20 to compile
apparently because of a multiplication at the line:=20 "src[i*10]";
 
Here's my source code:
 
#include <stdio.h>
#include=20 <string.h>
#include <stdlib.h>
 
void main()
{
int i;
char *src = =3D (char=20 *)malloc(100);
char *dest =3D (char *)malloc(20);
 
strcpy(src,"ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ")= ;
 
for (i=3D0; i<5; i++) dest[i] =3D = src[i*10]; /*=20 ERROR */
 
dest[5]=3D0;
 
printf("\r\nSrc says: %s \r\nDest says: = %s\n", src,=20 dest);
 
free(src);
free(dest);
}
 
 
------=_NextPart_000_0005_01C067A5.CE54C2A0--