sorry. was i that unclear? hm, maybe i should start working on my english instead of my programming
but anyways thanks for helping, this forum is great!
best resource i have seen in a long time!!
thanks!!!!!
p.s i will make my self clearer with source code next time and take more consideration with my posts!
-chris
stuck converting a char to an integer
-
- Member
- Posts: 29
- Joined: Mon Jun 30, 2008 9:51 am
Re: stuck converting a char to an integer
Well feel free to ask any questions, but do make them clearer next time...
Jules
Jules
Re: stuck converting a char to an integer
Just to be sure, I would look at the standard functions strtol() and sprintf() - perhaps you are making your life more difficult than necessary.cjhawley001 wrote:any help or comments(bad or good) welcome..
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: stuck converting a char to an integer
As a game programmer we're entirely C++. Even the animators take an introductory course (they only get as far as STL), although the game design students have to do prototyping in Dark Basic .Omega wrote:Cargo Cult is just being nice. The Uni CS classes (at least where I am at) are just ridiculously weak. I don't buy books or even go to my CS classes, except for the exams (we turn our work in via Black Board) and I still get A's and B's.
Oh, and we have Rapid Application Development which is C# (the WinForms designer makes it simple to make level editor interfaces and the such rapidly), but altogether C# only constitutes 4.16% of the entire degree.
My OS is Perception.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: stuck converting a char to an integer
Thankfully that won't help here I knew a guy who handed in an assignment which was basically copied and pasted bits of our lecturer's sample code put together. He barely got a pass and the comment was something like:Combuster wrote:From my own experience, university C++ courses tend to teach cargo cult programming
Excellent quality code..
...
..If only you went beyond submitting the code I gave you in class.
So basically, the lecturer was commenting that his own code was of excellent quality!
I think it was him who was working on a physics demo (also made up of copy-and-pasted code he didn't know what it did) and wanted to make a block shoot out from the screen and I managed to convince him the code to do that was:
Code: Select all
throw new Block();
It's a pity that the fun ones don't last very long. Our programming class has dropped down to around 12 people now.
My OS is Perception.
Re: stuck converting a char to an integer
Hope this doesn't come too late, but I just needed an atoi myself, so here you go:
Output: 1337
Hope you enjoy.
Code: Select all
int atoi(char* string)
{
int i = 0;
int value = 0;
int zeroValue = '0';
const int slen = len(string);
for (i = 0; i < slen; ++i)
{
char c = string[i];
if (c < '0' || c > '9')
{
return -1;
}
value = 10 * value + (c - zeroValue);
}
return value;
}
Code: Select all
printf("Return = %d","1337");
Hope you enjoy.
Free energy is indeed evil for it absorbs the light.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: stuck converting a char to an integer
Solar is correct , make use of the standard functions , Do not reinvent wheel unecesserily .