Topic:   adding a string section [C]   (Read 17663 times)


0 Members and 2 Guests are viewing this topic.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
adding a string section [C]
« 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[];
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: adding a string section [C]
« Reply #1 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.
« Last Edit: November 04, 2011, 07:55:26 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: adding a string section [C]
« Reply #2 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/

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: adding a string section [C]
« Reply #3 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
« Last Edit: November 05, 2011, 05:56:36 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: adding a string section [C]
« Reply #4 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.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: adding a string section [C]
« Reply #5 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?
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: adding a string section [C]
« Reply #6 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

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: adding a string section [C]
« Reply #7 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.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: adding a string section [C]
« Reply #8 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.
« Last Edit: November 08, 2011, 07:01:39 PM by x »

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: adding a string section [C]
« Reply #9 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?
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

x


  • GMG-er

  • **


  • Posts: 247
Re: adding a string section [C]
« Reply #10 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.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: adding a string section [C]
« Reply #11 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.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: adding a string section [C]
« Reply #12 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.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to