Page 2 of 2
Re: stuck converting a char to an integer
Posted: Wed Jul 02, 2008 8:13 pm
by cjhawley001
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
Re: stuck converting a char to an integer
Posted: Wed Jul 02, 2008 8:27 pm
by suthers
Well feel free to ask any questions, but do make them clearer next time...
Jules
Re: stuck converting a char to an integer
Posted: Fri Jul 04, 2008 3:00 am
by Solar
cjhawley001 wrote:any help or comments(bad or good) welcome..
Just to be sure, I would look at the standard functions strtol() and sprintf() - perhaps you are making your life more difficult than necessary.
Re: stuck converting a char to an integer
Posted: Wed Jul 09, 2008 11:49 pm
by AndrewAPrice
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.
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
.
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.
Re: stuck converting a char to an integer
Posted: Thu Jul 10, 2008 12:11 am
by AndrewAPrice
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:
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:
and he was wondering why it was crashing, so he called the lecturer over to look at his code
It's a pity that the fun ones don't last very long. Our programming class has dropped down to around 12 people now.
Re: stuck converting a char to an integer
Posted: Thu Jul 10, 2008 1:03 am
by Omega
Hope this doesn't come too late, but I just needed an atoi myself, so here you go:
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;
}
Output: 1337
Hope you enjoy.
Re: stuck converting a char to an integer
Posted: Thu Jul 10, 2008 2:18 am
by DeletedAccount
Solar is correct , make use of the standard functions , Do not reinvent wheel unecesserily .