"scanf" an int but detect string as well
Hey all! Thanks for the continuous help on this forum. I would like to be able to add a part to the scanf when "STOP" is entered to stop and give and then sort int's that have already been inserted. I've been spending a few hours already trying to solve this problem. My book mentions atoi(), also looked into strtol() functions, and also sscanf(). I have wassted enough time on this last part of the program and am asking for immediate help. Thanks to all of the old timers on here posting lengthy replies almost immediately
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
int intcmp(const void *a, const void *b)
{
return (*(int *)a - *(int*)b);
}
int main( void )
{
int count, arr[MAX], key, *ptr;
printf("Enter %d integer values; press Enter after each.\n", MAX);
for (count = 0; count < MAX; count++)
scanf("%d", &arr[count]);
puts("Enter Enter to sort the values.");
getc(stdin);
// Sort the array into ascending order.
qsort(arr, MAX, sizeof(arr[0]), intcmp);
// Display the sorted array.
for (count = 0; count < MAX; count++)
printf("\narr[%d] = %d.", count, arr[count]);
puts("\nPress Enter to continue.");
getc(stdin);
return 0;
}
I've also tried this
Code:
scanf("%d %s", &arr[count], string);
or similar