473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Type mismatch error

What is the meaning for the error expression syntax and type mismatch
error.I am using turbo c++.can anybody correct the errors in the
folowing program.

Following program is to find matrix addition.

Thanks in advance.

#include<stdio.h>
int rows,cols,a[3][3],b[3][3];
void main()
{
int mat_add[3][3],i,j;
int enter(void);
int getting_mat_1(int a[][3]);
int getting_mat_2(int b[][3]);
enter();
getting_mat_1(a[][3]); /*line 10 expression syntax*/
getting_mat_2(b[][3]); /*line 11 same as above*/
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
mat_add[i][j]=a[i][j]+b[i][j];
for(i=0;i<rows;i++)
{
printf("\n");
for(j=0;j<cols;j++)
printf("%d",mat_add[i][j]);
}
}
int enter(void)
{
int i,j;
printf("Enter how many rows to be entered\n");
scanf("%d",&rows);
printf("Enter how many columns to be entered\n");
scanf("%d",&cols);
printf("Enter the matrix in the form\n1 0 1\n9 8 7\n7 5 2\n");
return(rows,cols);
}
void getting_mat_1(int a[][3])
{ /*line 37 type mismatch in
declaration*/
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",a[i][j]);
}
}
}
int getting_mat_2(int b[][3])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",b[i][j]);
}
}
}

Nov 20 '05 #1
6 3883

shan wrote:
What is the meaning for the error expression syntax and type mismatch
error.I am using turbo c++.can anybody correct the errors in the
folowing program.

Following program is to find matrix addition.

Thanks in advance.

#include<stdio.h>
int rows,cols,a[3][3],b[3][3];
void main()
{
int mat_add[3][3],i,j;
int enter(void);
int getting_mat_1(int a[][3]);
In the function body you are defining it as "void getting_mat_1()";
Hence the redeclaration error.
int getting_mat_2(int b[][3]);
enter();
getting_mat_1(a[][3]); /*line 10 expression syntax*/
getting_mat_2(b[][3]); /*line 11 same as above*/
The following will suffice.
getting_mat_1(a);
getting_mat_1(b);

void getting_mat_1(int a[][3])
{ /*line 37 type mismatch in
declaration*/
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",a[i][j]);
}
}
}
int getting_mat_2(int b[][3])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",b[i][j]);
}
}
}


Here is a code that compiles - Though i have not seen the output.

#include <stdio.h>

int rows,cols,a[3][3],b[3][3];

void main()
{
int mat_add[3][3],i,j;
int enter(void);
int getting_mat_1(int a[][3]);
int getting_mat_2(int b[][3]);
enter();
getting_mat_1(a);
getting_mat_2(b);
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
mat_add[i][j]=a[i][j]+b[i][j];
for(i=0;i<rows;i++)
{
printf("\n");
for(j=0;j<cols;j++)
printf("%d",mat_add[i][j]);
}

}

int enter(void)
{
int i,j;
printf("Enter how many rows to be entered\n");
scanf("%d",&rows);
printf("Enter how many columns to be entered\n");
scanf("%d",&cols);
printf("Enter the matrix in the form\n1 0 1\n9 8 7\n7 5 2\n");
return(rows,cols);
}

int getting_mat_1(int a[][3])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",a[i][j]);
}
}
}
int getting_mat_2(int b[][3])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",b[i][j]);
}
}
}

Nov 20 '05 #2
Sandeep wrote:
Here is a code that compiles - Though i have not seen the output.


I don't have the stamina
to explain even a small percentage
of what's wrong with that code.

--
pete
Nov 20 '05 #3

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Sandeep wrote:
Here is a code that compiles - Though i have not seen the output.


I don't have the stamina
to explain even a small percentage
of what's wrong with that code.

--
pete


LOL!

barry
Nov 20 '05 #4

pete wrote:
Sandeep wrote:
Here is a code that compiles - Though i have not seen the output.


I don't have the stamina
to explain even a small percentage
of what's wrong with that code.


Then Don't - I have not corrected his code logically. Far from that, I
have not even read what he wrote. Corrections were only made to the
syntax and why it was not compiling.

Nov 20 '05 #5

Sandeep wrote:
int getting_mat_1(int a[][3]);
int getting_mat_2(int b[][3]);
Array doesn't return anyhting so void should be declared instead of
int.

Here also void.

int getting_mat_1(int a[][3])
{ . ....................
.....................

}

Here also void

int getting_mat_2(int b[][3])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",b[i][j]);
}
}
}


But an error occured at run time .Each time when scanf is called it
terminates only when enter is pressed.It should be changed so that by
pressing spacebar it should be terminated.

Nov 20 '05 #6
shan wrote:
Sandeep wrote:
int getting_mat_1(int a[][3]);
int getting_mat_2(int b[][3]);
Array doesn't return anyhting so void should be declared instead of
int.


getting_mat_1 is a function and it can return any valid datatype that
you want. It is a matter of choice and design. You may want to return a
status code from your function to indicate success or failure. In that
case, use int. If you do not, you can use void.
Here also void.

int getting_mat_1(int a[][3])
{

. ....................
.....................

}


Here also void

int getting_mat_2(int b[][3])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",b[i][j]);
}
}
}


But an error occured at run time .Each time when scanf is called it
terminates only when enter is pressed.It should be changed so that by
pressing spacebar it should be terminated.


The run time error is happening because of the statement
"scanf("%d",b[i][j])". It should read "scanf("%d",&b[i][j])". Note the
"&". This denotes the address of b[i][j]th element.

I have made some changes to your program. The program is far from being
perfect for what you are trying to do. It reads two 3X3 arrays and adds
them. You should now try to improve it so that it can read a MXN array
and add them. Hope this helps.

#include <stdio.h>

// int enter(void); // No need for this function. A function should be
declared only when needed
// Since you are declaring your matrix "a" and "b" as 3X3,
// I am assuming that is what you needed. Try to improve the program
for MXN

int a[3][3],b[3][3];
void getting_mat(int a[][3]);

// No need to have mat1, mat2 . This is where a function helps
// Just use the same function to read the values

int main()
{
int mat_add[3][3];
int i,j;
printf("\nEnter first 3X3 matrix: \n");
getting_mat(a);
printf("\nEnter second 3X3 matrix: \n");
getting_mat(b);

for(i=0;i<3;i++)
for(j=0;j<3;j++)
mat_add[i][j]=a[i][j]+b[i][j];
printf("\nThe addition of matrix a and b\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",mat_add[i][j]);
}

}

void getting_mat(int a[][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
}

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from...
1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
3
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line...
1
by: Brett | last post by:
I have a form that calls a method within a DLL. By clicking a button on the form, the DLL is instantiated and the SaveOutlookMessage() method invoked. The DLL code copies messages from Outlook to...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
1
by: jodyblau | last post by:
I have a database which works fine until I create and MDE file. Once I create the MDE, when I open a particular form I get a "Type Mismatch" error. Because its an MDE file, I can't step through...
19
by: zz12 | last post by:
Hello, is there a setting in IIS 5.0 that would quickly fix the following error?: Microsoft VBScript runtime (0x800A000D) Type mismatch It's strange because some of our .asp pages were...
1
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.