Monday, 5 February 2018

Basic c program doesn't continue after the final scanf in the function, scanf just keeps accepting input endlessly

Here is relevant code:




I am somewhat new to the world of c so please help me out
The problem is at the bottom of the code: the divider = getchar()
this bit of code gets the program stuck and it never progresses after that it. Its just an infinite loop of allowing input. What is wrong. Please be specific as I am not entirely familiar with complex concepts (though I am eager to solve this issue no matter how complex the solution may be)



void read_in(int n, int m)
{

int a = 0, b = 0, i = 0, x;

while (a != n && b != m)

{
if (b == 0 && i == 0)
{
printf("\nEnter row %d: ", a);

}

scanf("%d", &array[a][b]);

diglength[a][b] = floor (log10 (abs (array[a][b]))) + 1;


if (b == m - 1)
{
a++;
b = -1;
}
if (b == -1 && i != 0 && a != n)
{
printf("\nEnter row %d: ", a);
}


i++;
b++;
}

printf("\nEnter the number of new lines in between rows: ");
scanf("%d", &newlines);
printf("\nEnter the span of each array element: ");

scanf("%d", &span);


check_span(n, m);
getchar();
printf("\nEnter the type of justification (l - left r - right): ");

just = getchar();

while (just != 'r' && just != 'l')
{
printf("\nInvalid argument");

printf("\nEnter the type of justification (l - left r - right): ");
scanf(" %c", &just);
}

printf("\nEnter the character to be placed in between elements: ");
getchar();
divider = getchar();
//THE PROGRAM NEVER GETS PAST HERE IT GETS STUCK ON THE ABOVE CHARACTER ASSIGNMENT...WHY

printf("it got here "); printf("%c", divider);

}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...