delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/16/15:27:23

Message-ID: <000401c0679d$d5101020$ce3dfac1@franck>
From: "Franck Bauquier (Defcon1)" <defcon1 AT free DOT fr>
To: <bug-g++@prep.ai.mit.edu>, <djgpp AT delorie DOT com>
Subject: Cannot multiply
Date: Sat, 16 Dec 2000 21:18:59 +0100
MIME-Version: 1.0
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 <stdio.h>
#include <string.h>
#include <stdlib.h>

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi!</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>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<BR>it in DEST, thus DEST would be filled with=20
"AAAAA".<BR>Unfortunately, although it's working under Turbo C++, DJGPP =
refuse=20
to compile<BR>apparently because of a multiplication at the line:=20
"src[i*10]";</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here's my source code:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#include &lt;stdio.h&gt;<BR>#include=20
&lt;string.h&gt;<BR>#include &lt;stdlib.h&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>void main()<BR>{<BR>int i;<BR>char *src =
=3D (char=20
*)malloc(100);<BR>char *dest =3D (char *)malloc(20);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>strcpy(src,"ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ")=
;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>for (i=3D0; i&lt;5; i++) dest[i] =3D =
src[i*10]; /*=20
ERROR */</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>dest[5]=3D0;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>printf("\r\nSrc says: %s \r\nDest says: =
%s\n", src,=20
dest);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>free(src);<BR>free(dest);<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0005_01C067A5.CE54C2A0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019