Hello there.
Please see the code I have written below
void main(void)
{
int a[MAX];
int i, count=0;
printf("Enter vectors. Enter 666 to stop.\n\n");
for(i=0;i<MAX;i++)
{
printf("Vector %i: ", i+1);
scanf("%i", &a);
count++;
if(a == 666)
{count--;break;}
}
I am attempting to input an array of integers, and stop entering those integers either with a blank line, or a word. Anything but 666! It's so tacky.
I have tried %s in scanf and typecasting to an int, but that still does not terminate the loop when I substitute 666 for "stop" in the if statement.
I'm sure it's something simple, any suggestions?
Thanks,
Fraser
Please see the code I have written below
void main(void)
{
int a[MAX];
int i, count=0;
printf("Enter vectors. Enter 666 to stop.\n\n");
for(i=0;i<MAX;i++)
{
printf("Vector %i: ", i+1);
scanf("%i", &a);
count++;
if(a == 666)
{count--;break;}
}
I am attempting to input an array of integers, and stop entering those integers either with a blank line, or a word. Anything but 666! It's so tacky.
I have tried %s in scanf and typecasting to an int, but that still does not terminate the loop when I substitute 666 for "stop" in the if statement.
I'm sure it's something simple, any suggestions?
Thanks,
Fraser