View previous topic :: View next topic |
Author |
Message |
user-begginer Guest
|
mathematics for begginer |
Posted: Mon Jan 17, 2005 3:09 pm |
|
|
Help me please with this: for lcd - output
I have variable number a=344567 - variable!
I need to make b=44567, or b=4567, or b=567, or 67, or 7 if I know only
were I must do it . for example
a=344567
c=3
then I need b=567;
very begginner. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 17, 2005 3:33 pm |
|
|
The easiest way is to convert the number to a string using something like itoa() or sprintf(). Then use c as the index to the array.
Code: |
char buf[16];
char *ptr;
sprintf(buf,"%u",a); // for unsigned int
ptr = &buf[c]; // ptr now points to the string you want
|
I don't think you really need the data to be an actual number. If you do, then
|
|
|
user-begginer Guest
|
thanks, Mark |
Posted: Mon Jan 17, 2005 3:49 pm |
|
|
thanks a lot I'm realy need actual - but without any printf and sprintf, for
my output I need only number in unsigned int32 |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Jan 17, 2005 4:56 pm |
|
|
The easiest (but very inefficient) way of doing it is:
Code: |
#include <math.h>
c=a%pow(10,b);
|
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 17, 2005 6:08 pm |
|
|
If c=1 does b=44567 or 7 |
|
|
user-begginer Guest
|
|
Posted: Mon Jan 17, 2005 9:21 pm |
|
|
b=7; |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jan 18, 2005 6:48 am |
|
|
|
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jan 18, 2005 3:58 pm |
|
|
Yeah sorry, it was my mistake, it should be
Code: | #include <math.h>
b=a%pow(10,c); |
Mark, ^ is XOR |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jan 18, 2005 7:53 pm |
|
|
Yeah been programming in VB this week |
|
|
|