delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/29/00:46:17

From: "Jason Nehf" <zolaar AT earthlink DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: trouble compiling
Date: Sun, 28 Jun 1998 23:18:01 -0500
Organization: EarthLink Network, Inc.
Lines: 60
Message-ID: <6n749v$sqr$1@fir.prod.itd.earthlink.net>
NNTP-Posting-Host: 1cust28.tnt2.chi5.da.uu.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This problem will probably be gone by the time you read this, but I need
help.  I am trying to use the random number generator included in DJGPP
random();  I think i know the syntax:

int random() % MaxNum;

Which returns an integer between 0 and MaxNum.  I know how to seed it, using
srandom(), so I think i'm good there.  The problem isnt really with the
random number thing.  Its with itoa();  If anyone doesnt know what this is
(you should, unless there's a better routine to change from int to *char,
and i HOPE there is), it (duh) puts an int int a *char.  Meaning if you pass

itoa(num, string, 10);

it will take num (which 10 makes it a base-10 number) and put it into the
*char string.  Easy, huh?  Well, not so easy - whenever i try to use it, it
gives me a call frame traceback, and says it happened in itoa.  This
frustrates me because, as far as i know, this is the only way to convert
from int to *char, and textout only uses *char.

PLUS

for some reason, i can't get texout to work - it gives me a parse error when
i compile, saying Parse Error before ','
I dont know what this means - when it gives it to me and the parse error is
before a parenthasis or something, it usually means a semi-colon is missing
the line above it, but this is not the case.  If someone has some insight as
to why this isnt working, please help me!  I'm about ready to rip my monitor
off its mountings and throw it through the wall!  :-)
Oh, and here's the smallest amount of code that will do both of these
errors, just like you people like it.  Its a snippet, so dont expect this
whole thing to compile.  Eh, i'll edit it so it does, to make your life
easier:

#include <stdlib.h>
#include <stdio.h>                  /*I only added this as a habit.  if you
dont need these headers*/
#include <iostream.h>            /*you can edit them out.*/
#include "allegro.h"


int main()
{

    allegro_init();
    set_color_depth(8);
    set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
    text_mode(0);
    char *c;
    int p;
    p=3;
    itoa(p, c, 10);  // call frame traceback here

    textout(screen, FONT, c, 10, 10, 15); // parse error  before ',' here
}


Thank you!!!


- Raw text -


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