How can I do it - with pointer and only one loop ?

for exmpl function - unsigned int dif(const char *str)

counter = 0;
for(i = 0; i < N; i++)				
A[i] = 0;
do									
{
	A[tmp % 10]++;			
	tmp /= 10;
}
while(tmp);
for(i = 0; i < N; i++)
if(A[i])counter++;					
printf("\n\nThere r %u different digits in the number %u\n",counter , n);

Recommended Answers

All 4 Replies

u dint define tmp... wat is tmp actually??

I read this posting a few times and I'm at a loss..Do you mean if you have a number say:

unsigned int myint = 87456;

do you want to extract from it 8 - 7 - 4 - 5 - 6?

No, I want like that 87456 - we have 5 different digits (It's all what I want)

one more exmp - number 113452266 - we have 6 different digts
I did it with two loops but i don't know - how to do it with 1 loop and pointers :)

No, I want like that 87456 - we have 5 different digits (It's all what I want)

one more exmp - number 113452266 - we have 6 different digts
I did it with two loops but i don't know - how to do it with 1 loop and pointers :)

so you have a number defined as

unsigned int myint = 113452266;

and you want to extract the number of unique digits from myint?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.