The c variable in the for loop, only goes from 0 to 9, so 10 rows. It will automatically quit and can't run over that amount, unless you change your code.
So I don't know what "trick" you're referring to.
Printable View
The c variable in the for loop, only goes from 0 to 9, so 10 rows. It will automatically quit and can't run over that amount, unless you change your code.
So I don't know what "trick" you're referring to.
guys i have class in an hour I wont bug u again today
please help me understand how I can exit the program if the user enter more than 10 rows
i want to display an error code myself to the user
You mean if m > 10?
You're tough to nail down here.
well yeah if m>10 i can write that down in the beginning
but what if c >10 (number of rows)
C can't be more than 10:
Code:for( c = 0 ; c < 10 ; c++ )
okay thanks :)
for the EOF when i enter the value of the input and press CTRL-Z the whole program just stops
Don't enter the value, and then enter EOF, at the same time. Enter your values <hit enter>. Next loop, when you want to quit, press the EOF key combo.
I know thats exactly what im doing but its not working
what if instead of 99 i want to assign a * as end of program how would i do that
like char *;
oh and dont worry ill change my variable names
Post your current code, so I can see what's doing.
Are you testing user's entry for EOF?
Code:#include<stdio.h>
#include<stdlib.h>
int main()
{
int val, m,x, n, c = 0, d,k, matrix[10][10], transpose[10][10], product[10][10]; //defining variables
printf("Enter the number of columns of matrix ");
scanf("%d",&m);
if(m<=0 || m>10){ //error checking if user enter negative number or 0 for column
printf("You entered a invalid value.\n");
exit(0);
}
else{
printf("Enter the elements of matrix \n");
for( c = 0 ; c < 10 ; c++) //forst for loop to scan the matrix
{
for( d = 0 ; d < m ; d++ )
{
scanf("%d",&matrix[c][d]);
if (matrix[c][d] == 99) // 'x' is character variable I declared to use as a break
break;
if (matrix[c][d] < 0){ //error checking if any entries in the matrix are negative
printf ("you entered an invalid number\n");
exit(1);}
}
if (matrix[c][d] == 99)
break;
}
}
if (d > 0){ //error checking to make sure the number of entries is correct
printf("The number of entries is not valid\n");
exit(1);
}
printf("\nHere is your matrix:\n");
int i; //declaring i to be count for row
for(i=0;i<c;i++)
{
for(d=0;d<m;d++)
{
printf("%3d ",matrix[i][d]);
}
printf("\n");
}
my bad
Code:#include<stdio.h>
#include<stdlib.h>
int main()
{
int val, m,x, n, c = 0, d,k, matrix[10][10], transpose[10][10], product[10][10]; //defining variables
printf("Enter the number of columns of matrix ");
scanf("%d",&m);
if(m<=0 || m>10){ //error checking if user enter negative number or 0 for column
printf("You entered a invalid value.\n");
exit(0);
}
else{
printf("Enter the elements of matrix \n");
for( c = 0 ; c < 10 ; c++) //forst for loop to scan the matrix
{
for( d = 0 ; d < m ; d++ )
{
scanf("%d",&matrix[c][d]);
if (matrix[c][d] == EOF) // 'x' is character variable I declared to use as a break
break;
if (matrix[c][d] < 0){ //error checking if any entries in the matrix are negative
printf ("you entered an invalid number\n");
exit(1);}
}
if (matrix[c][d] == EOF)
break;
}
}
if (d > 0){ //error checking to make sure the number of entries is correct
printf("The number of entries is not valid\n");
exit(1);
}
printf("\nHere is your matrix:\n");
int i; //declaring i to be count for row
for(i=0;i<c;i++)
{
for(d=0;d<m;d++)
{
printf("%3d ",matrix[i][d]);
}
printf("\n");
}
OK, the check is in there. Did you get it working the way you wanted it to?
If not, describe when the EOF test should make the entry of numbers, quit.