Game Maker's Garage Forum

Game Creation => Code Exchange => Topic started by: GMG Kurt on November 04, 2011, 06:34:34 PM

Title: adding a string section [C]
Post by: GMG Kurt on November 04, 2011, 06:34:34 PM
So I'm working on a function to suffix a character string with a decimal. In C. To do this it would require adding another data cell at the end of it. I'm using dynamic arrays for this.
Code: [Select]
char c[];
Title: Re: adding a string section [C]
Post by: GMG Kurt on November 04, 2011, 07:46:36 PM
epiphany!

I can't add a new data storage at the arrays at the specific point of the array, because I allocated a new variable in front of it.

Not to say I can't reallocate it! I'll post the source code later still have to make it ;D 8)

EDIT: reallocating as a dynamic array naturally.
Title: Re: adding a string section [C]
Post by: x on November 05, 2011, 06:02:08 AM
Use a pointer to a block of memory, then realloc it to the new size you need.

http://www.cplusplus.com/reference/clibrary/cstdlib/realloc/
Title: Re: adding a string section [C]
Post by: GMG Kurt on November 05, 2011, 09:12:57 AM
Thanks that worked... to an extent. The array inside the function was passed through the function, so I couldn't reallocate it, but the overarching array that keeps getting passed around will now have to be dynamically allocated. :-/

Thank you ;D

EDIT: I have to finnish tomorrow, thats my goal, and I think it's in reach... I hope it's in reach :-X
Title: Re: adding a string section [C]
Post by: x on November 05, 2011, 09:32:24 PM
Quote
Thanks that worked... to an extent. The array inside the function was passed through the function, so I couldn't reallocate it, but the overarching array that keeps getting passed around will now have to be dynamically allocated. :-/

Thank you ;D

EDIT: I have to finnish tomorrow, thats my goal, and I think it's in reach... I hope it's in reach :-X

If you get stuck feel free to ask me, I have a lot of experience with C/++ and especially memory management... unfortunately.
Title: Re: adding a string section [C]
Post by: GMG Kurt on November 07, 2011, 07:54:05 PM
cool thanks. I've had experience with C programs, but not much with memory management.;D

If you don't mind me asking do you know anything about assembly C? You know like using C to make Operating systems like Linux?
Title: Re: adding a string section [C]
Post by: x on November 07, 2011, 10:38:44 PM
Quote
cool thanks. I've had experience with C programs, but not much with memory management.;D

If you don't mind me asking do you know anything about assembly C? You know like using C to make Operating systems like Linux?

I know there's no way you can touch anything OS related without knowing basic memory management.

And yes, but only vaguely. I did a unit on Operating Systems in uni, and we had to dabble in Unix/Linux coding
Title: Re: adding a string section [C]
Post by: GMG Kurt on November 08, 2011, 06:28:29 PM
cool I've been wanting to get into OS programming for a while now. Do you know a good place to start? :D

I do know the basics of C memory management, it's just that I'm only just starting to practically apply the things I know. Previously I thought I was great at it, but my current project has been an eye opener (that I'm a n00b at mm). I think next time I'll try something like a dynamic doubly linked list rooted in memory management.
Title: Re: adding a string section [C]
Post by: x on November 08, 2011, 07:00:27 PM
Quote
cool I've been wanting to get into OS programming for a while now. Do you know a good place to start? :D

I do know the basics of C memory management, it's just that I'm only just starting to practically apply the things I know. Previously I thought I was great at it, but my current project has been an eye opener (that I'm a n00b at mm). I think next time I'll try something like a dynamic doubly linked list rooted in memory management.


My suggestion is that you never start in OS programming -- its horribly complex and boring stuff. If you are desperate take the OS course at university when you get to it, or a buy a nice book on the subject and read through it all. Its one of those things where you need to do a mountain of theory before you can start on practice. Trust me on that.

Stick to games, its more fun and theres more money in it.
Title: Re: adding a string section [C]
Post by: GMG Kurt on November 09, 2011, 05:46:25 PM
I really hoped you wouldn't say something like that :-/
are you sure theres no library, or documentation online thats worth a look-over that I could at least glance at?
Title: Re: adding a string section [C]
Post by: x on November 10, 2011, 08:57:00 PM
Quote
I really hoped you wouldn't say something like that :-/
are you sure theres no library, or documentation online thats worth a look-over that I could at least glance at?

An entire open source Linux OS.

Operating systems are the most complex thing in computer science -- barring artificial intelligence maybe. They are also very boring. I recommend you buy a good book, then take the course in university. Theres now "how to make an OS for dummies" guide. Its not the kind of thing you can learn to do in a few months.

This is the book we used as a text book in my unit: http://www.amazon.com/Operating-Systems-Internals-Design-Principles/dp/013230998X/ref=sr_1_cc_2?s=gift-cards&ie=UTF8&qid=1320980174&sr=1-2-catcorr

I thought it covered the basics quite well, but I am no expert.
Title: Re: adding a string section [C]
Post by: Gan on November 10, 2011, 09:34:31 PM
You could do what I did, start small and make a fake OS.
I made Doors OS in SilverCreator.

Lack of objects made it tough but it had resizable windows and draggable folders.
Title: Re: adding a string section [C]
Post by: GMG Kurt on November 11, 2011, 06:44:04 PM
theres a guy making a game device like the nD, and he asked me to do the OS programming for it. I said I'd love too, but had to look into it. Not going well so far sadly :-/

That was actually one 3 reasons I wanted to become a programmer: Make a Game console.