delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/20/21:18:03

From: James W Sager Iii <sager+@andrew.cmu.edu>
Newsgroups: comp.os.msdos.djgpp
Subject: newbie error, or are my pointers fuxing
Date: Tue, 20 Mar 2001 21:02:51 -0500
Organization: Carnegie Mellon, Pittsburgh, PA
Lines: 47
Message-ID: <Yui0j=i00UjLEHS0Uq@andrew.cmu.edu>
NNTP-Posting-Host: po7.andrew.cmu.edu
X-Trace: bb3.andrew.cmu.edu 985140327 5890 128.2.10.107 (21 Mar 2001 02:05:27 GMT)
X-Complaints-To: advisor AT andrew DOT cmu DOT edu
NNTP-Posting-Date: 21 Mar 2001 02:05:27 GMT
X-Added: With Flames (outnews v2.6)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I had a problem earlier with pointers messing my game up.

I'd send 1 adress to a function, but it'd recieve a different one. 
Really weird stuff...

Anyway, I was wondering:


void stupid_newbie function(char *c1)
{
char a[40];

strcpy(a,c1);

cout<<a;
}

If I pass:

stupid_newbie_function("Hello.");
stupid_newbie_function("world.");

It will type: Hello
then a Segfault pops up.

if I do:
char b[40];
strcpy(b,"Hello");
stupid_newbie_function(b);
strcpy(b,"World");
stupid_newbie_function(b);

It gives me:
HelloWorld


So is this me being a stupid rusty programmer?
Or is it due to my program having a memory leak I still need to track down?


I haven't got back in my groove yet... still mega rusty
All I want to do is design games, I hate code.


Thanks for reading,
                James Sager

- Raw text -


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