Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m writing a program that involves requesting input from the user for random a

ID: 3557658 • Letter: I

Question

I'm writing a program that involves requesting input from the user for random amount of integers, which terminates after the user returns a blank. These integers are then put into an array, which I use for sorting the integers later. The program essentially runs as follows:

Enter a list of integers:
> 5

> 0

> 3

>4

etc... until the user enters
>

which is a blank.

The program then sorts the integers.

My snippet of code is:

static int GetIntegerArray(int array[], int max)
{
   int n, value;
  
   n = 0;
  
   while(1) {
       printf("> ");
       value = GetInteger();
       if (value == "") break;
       if (n == max) Error("Too many input items for array");
       array[n] = value;
       n++;
   }
   return(n);
}

and I get the error "Warning: comparison between pointer and integer" where value == ""

The number of elements is random, and I set the max number of possible elements to 1000 to account for this. Help would be greatly appreciated!!

Explanation / Answer

your getinteger() function might be returning a pointer.

best way is to do like this

while(scanf("%d",&value))

{

if(n < max) array[n] = value;;

else break;

n++

}

this line shall not only stop at blank but also after any other thing which is not integer