CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

mathematics for begginer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
user-begginer
Guest







mathematics for begginer
PostPosted: Mon Jan 17, 2005 3:09 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 17, 2005 3:33 pm     Reply with quote

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
Code:

  b = atoi(ptr);
user-begginer
Guest







thanks, Mark
PostPosted: Mon Jan 17, 2005 3:49 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 17, 2005 4:56 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 17, 2005 6:08 pm     Reply with quote

If c=1 does b=44567 or 7
user-begginer
Guest







PostPosted: Mon Jan 17, 2005 9:21 pm     Reply with quote

b=7;
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 18, 2005 6:48 am     Reply with quote

Code:
b=a%(10^c);
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Jan 18, 2005 3:58 pm     Reply with quote

Yeah sorry, it was my mistake, it should be

Code:
#include <math.h>

b=a%pow(10,c);



Mark, ^ is XOR Very Happy
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 18, 2005 7:53 pm     Reply with quote

Yeah Embarassed been programming in VB this week Laughing
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group