473,769 Members | 3,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(i nt a[][3]);
int getting_mat_2(i nt 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",&row s);
printf("Enter how many columns to be entered\n");
scanf("%d",&col s);
printf("Enter the matrix in the form\n1 0 1\n9 8 7\n7 5 2\n");
return(rows,col s);
}
void getting_mat_1(i nt 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(i nt 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 3906

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(i nt a[][3]);
In the function body you are defining it as "void getting_mat_1() ";
Hence the redeclaration error.
int getting_mat_2(i nt 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(i nt 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(i nt 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(i nt a[][3]);
int getting_mat_2(i nt 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",&row s);
printf("Enter how many columns to be entered\n");
scanf("%d",&col s);
printf("Enter the matrix in the form\n1 0 1\n9 8 7\n7 5 2\n");
return(rows,col s);
}

int getting_mat_1(i nt 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(i nt 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*****@mindsp ring.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(i nt a[][3]);
int getting_mat_2(i nt b[][3]);
Array doesn't return anyhting so void should be declared instead of
int.

Here also void.

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

}

Here also void

int getting_mat_2(i nt 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(i nt a[][3]);
int getting_mat_2(i nt 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(i nt a[][3])
{

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

}


Here also void

int getting_mat_2(i nt 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",m at_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
4439
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 the table datingnew the value of the ident field.
1
2493
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 True. I then have an if statement to determine what to write to the screen depending on blnNoData. As long as the if statement is true (doesn't have to go to the else clause), the code runs fine. Otherwise, a type mismatch error is returned. In...
4
11967
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 14 (STDCOST). ---End Error Msg--- The STDCOST is set to decimal (28,14) and is a formatted in Access as a number, single with 14 decimal. I don't know why I would be getting a Type
0
2254
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 that will run fine without any criteria but as soon as I add any criteria it gives a "Data type mismatch" error. As soon as I remove any criteria it runs perfectly. I know this query is based on another query but I have other processes based on...
3
2916
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 347: 'response.Write(sql2)
1
2817
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 an HTML file. When I execute the EXE, which is only the form, and click the button, I get a "Type Mismatch" error on this line in the form: mailobj.SaveOutlookMessage() Any suggestions on why I'm getting the type mismatch error? --Form code
6
5999
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 class has stuff initialized by calling a sub SetClass that wants some Word specific objects passed-in. If the user mistakingly uses the wrong object, say, uses an Excel object
1
1671
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 the code to find out where the error is occuring; and (as I mentioned earlier) when I go back to the oriignal database the problem doesn't exist. Any ideas of what is going on here and how to fix it? Thanks,
19
5545
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 working fine for the past years but recently our website was updated in that old folders were renamed and the new ones took on the existing name and was wondering why some our ..asp pages are now returning this error? I would think that since the code
1
2838
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 has ended up in my lap i guess. This is the issue: There is an access database that pulls data from a list of excel spread sheets. This access database and excel files are stored on a server. When the database requests info from the excel file...
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.