468,513 Members | 984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

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 5329
Banfa
9,056 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
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.