Good afternoon, needs help in debugging a program code

Hello! I am a newbie to C++ I hope you can help me in creating a program. I have a code but it doesn't seem to work... Please help me. I am trying to create a program that accepts any number of integers (positive and negative) as input and
saves it as an array of integers. The string “---eee13---”, which will be typed by the user will be the signal of the program to stop accepting inputs. Then, it will print all the integer inputs. The program
should have the capability to disregard inputs that are not integers.

This is my code:


int main (void)
{
int count = 0;
char input[256];
int finalinput[1024];
int inputcount = 0;
int a = 0, b = 0, c = 0;

printf ("Enter integers:");
fgets(input, sizeof(input), stdin);

while (input[] != "---eee13---") {
a = strlen(input) - 1;
printf ("%d\n", a);
while (input[count] != '\n') {
if (('input[count]' >= 48 && 'input[count]' <= 57) || input[count] == '-') {
while (count < a && ('input[count]' >= 48 && 'input[count]' <= 57)) {
count++;
}
if (count == a) {
finalinput[c] = atoi(input);
inputcount++;
c++;
}
}
else break;
}
input[0] = '\0';
fgets(input, sizeof(input), stdin);
count = 0;
}

printf ("%d", finalinput[0]);
printf ("%d", inputcount);

return 0;
}


When I input - , the program just exits.
Last edited on
getch(); on the end so the program won't exit after your first input
Hello Jorz!

The thing is that when I enter integer, the code works fine but if I enter '-', it goes out...
you go in to the
if (('input[count]' >= 48 && 'input[count]' <= 57) || input[count] == '-')
{
while (count < a && ('input[count]' >= 48 && 'input[count]' <= 57)) {

then it will never do the while if the char is -

so the if doesn't do anything with -

let me know if I am wrong
Last edited on
yep
Last edited on
Need help pls... I have a code but it doesn't seem to work... Please help me. I am trying to create a program that accepts any number of integers (positive and negative) as input and saves it as an array of integers.

The string “---eee13---”, which will be typed by the user will be the signal of the program to stop accepting inputs. Then, it will print all the integer inputs.

The program should have the capability to disregard inputs that are not integers.

I have posted my code above... Any help is very much appreciated..Thanks
Yes Jorz, you are correct...
Topic archived. No new replies allowed.