471,047 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,047 software developers and data experts.

how to use char* to store digit

1
hi i have a question on c++

can u tell me how we use char* to store digits?????
and the digits are characters.....
thx..
hurry!!!
Sep 24 '06 #1
1 5412
Banfa
9,065 Expert Mod 8TB
You can not use char 8* to store digits directly because it is a pointer to a location that stores digits not a place to store digits.

You would have to do it indirectly

Expand|Select|Wrap|Line Numbers
  1. char *pDigits;
  2. int i;
  3.  
  4. pDigits = malloc(11);
  5.  
  6. for( i=0; i<10; i++)
  7. {
  8.     pDigits[i] = (char)('0' + i);
  9. }
  10.  
  11. pDigits[10] = '\0';
  12.  
  13. printf("Digits: %s\n", pDigits);
  14.  
Sep 24 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

18 posts views Thread by muser | last post: by
22 posts views Thread by hantie | last post: by
13 posts views Thread by Nicholas | last post: by
5 posts views Thread by rajus | last post: by
80 posts views Thread by Gaijinco | last post: by
33 posts views Thread by Prasad | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.