Lately I've been trying a few exercises and examples a tutorial on YouTube gave its viewers. It all worked fine until I decided to put a scanf function to get user input.
After that everything appeared to stall leaving the terminal blank and only when i terminated the application the program's output appeared. What might be going wrong? I'm using Eclipse as IDE and mingw-64 as compiler
#include <stdio.h>
#include <stdlib.h>
int sum(int* iterator, int* bound) {
int sum = 0;
while(iterator <= bound){
sum += *iterator;
iterator++;
}
return sum;
}
int main() {
int at[] = { 1,2,4,6,7,-5,-3 };
int* bound = &at[sizeof(at)/sizeof(int)-1];
printf( "Sum of array is : %d \n" ,sum(at, bound));
int matrix[3][3] ={{1,2,3},{4,5,6},{7,8,9}};
for( bound = &matrix[0][0]; bound <= &matrix[2][2]; bound++){
printf(" %d ", *bound);
}
And the piece of code after adding the scanf function
#include <stdio.h>
#include <stdlib.h>
int sum(int* iterator, int* bound) {
int sum = 0;
while(iterator <= bound){
sum += *iterator;
iterator++;
}
return sum;
}
int main() {
int at[] = { 1,2,4,6,7,-5,-3 };
int* bound = &at[sizeof(at)/sizeof(int)-1];
printf( "Sum of array is : %d \n" ,sum(at, bound));
int matrix[3][3] ={{1,2,3},{4,5,6},{7,8,9}};
for( bound = &matrix[0][0]; bound <= &matrix[2][2]; bound++){
printf(" %d ", *bound);
}
int s=3;
printf("Give a number: ");
scanf("%d",&s);
printf("%d", s);
return 0;
}