Read value from adress with pointers

0 Aybars Arslan · March 4, 2015
Hello, I need to some help.

i want to write some numbers till write 0, when i wrote 0 the program must be stop and show the numbers in order, anybody can help me ? 

its almost finish but i have one problem.
it my code  :  http://codepaste.net/8ezhjk

i mustn't use array, its forbidden :) 

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · March 4, 2015
you can use a linked list and place the numbers into their respective positions as you enter them in.
0 Aybars Arslan · March 5, 2015
its forbidden to use lists

but i solve the problem its answer


#include
#include
#include

int main()
{
   int* number;
   int i = 0, j = 0;

   number = (int*)malloc(2000);

   do{
       printf("Enter a number : ");

       scanf("%d",number+i);
/*   TEST
       printf("\n######\n");
       printf("%d. number = %d \t%p\n",i+1,*(number+i),number+i);
       printf("\n######\n");
*/
       i++;
   }while(*(number+i-1) != 0);

   printf("\n!!!!############!!!!\n\n");
   for(j = 0 ; j < i; j++){
//TEST      printf("%d. number = %d \t%p\n",j+1,*(number+j),number+j);
       printf("%d. number = %d\n",j+1,*(number+j));

   }
   return 0;
}
0 Dol Lod · March 5, 2015
I thought you said you weren't allowed arrays, but number is a dynamically allocated array. An alternative is a queue to show everything in order unless you mean that you can't use collections at all. 
0 Clark Alaan · April 12, 2015
Well, an alternative would also be using encryption using shift operators. Unfortunately I haven't played around with them too much so I don't know how to teach you. :(
  • 1

C

106,959 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator