I think you have a misconception of what the program is intended to do. If the program is called as such: rather than
Code:
./gauss < gauss1.txt
then it should not wait for any input, but instead return
Code:
Expected N (number of equations)
and nothing further.
After having implemented your code my program looks like
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXROWS 100
#define MAXCOLS 101
void printMatrix(int rows, int columns, double matrix[][MAXCOLS]);
void clean_buff( void);
/* Add helper functions and global variables here */
int main()
{
/* Add your implementation here */
int i = 0;
int rows;
int r,c;
scanf("%d",&rows);
double matrix[rows][rows+1];
//scanf("%lf",&matrix[0][0]);
double num = 0;
/*for (r = 0; r < rows; r++) {
for (c = 0; c < rows+1; c++) {
if((scanf("%lf",&num)) != EOF){
//printf("scanned: %lf\n",num);
matrix[r][c] = num;
printf("m[%d][%d] = %lf\n",r,c,matrix[r][c]);
}else{
printf("Element a[%d][%d] is missing\n",r,c);
exit(0);
}
}
}*/
for(r=0; r < rows; ++r){
for(c = 0; c < rows+1; ++c){
scanf("%lf",&matrix[r][c]);
}
clean_buff();
}
//printf("%d, %d\n",r-1,c-1);
printf("\t\ttest: %lf\n",matrix[1][0]);
printf("initial matrix\n");
printMatrix(rows,rows+1,matrix);
return 0;
}
void clean_buff( void ){
int ch;
while (( ch = getchar() ) != EOF && ch != '\n');
}
void printMatrix(int rows, int columns, double matrix[][MAXCOLS])
{
/* Add your implementation here */
int j, k;
printf("MATRIX: \n");
//printf("rows = %d\n",rows);
//printf("columns = %d\n",columns);
for (j = 0; j <= rows; j++) {
for (k = 0; k < columns; k++){
printf("m[%d][%d] : %lf\n",j,k,matrix[j][k]);
}
}
}
After typing
Code:
gcc test.c -o test1
./test1
the program will sit and await user input.
If I type any amount of characters and press return it says "Illegal Instruction" and terminates