473,387 Members | 1,575 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.

Help with C errors C2440 and C2664.

pttempmonthaddr = &tempmonth;
pttempdayaddr = &tempday;

separate(date, pttempmonthaddr, pttempdayaddr);/*function call*/
printf("\nThe month entered is %s and day entered is %f.\n", pttempmonthaddr, *pttempdayaddr);
return 0;

error C2440: '=' : cannot convert from 'char (*__w64 )[81]' to 'char *'

error C2664: 'separate' : cannot convert parameter 3 from 'int *' to 'int'
There is no context in which this conversion is possible


I am getting the C2440 error in the top line and C2664 error in the 3rd line from top. Can somebody help me out as to why?
Feb 10 '08 #1
2 2295
weaknessforcats
9,208 Expert Mod 8TB
Probably your array definition has something top do with the C2440.

The C2664 is caused by a mismatch in the type of the third argument versus what you supplied. It looks like the third argument needs to be an int and you supplied an int*

I can't tell since you didn't post the definitions of your variables or your function prototype.

You mioght read this on arrays:
First, there are only one-dimensional arrays in C or C++. The number of elements in put between brackets:
Expand|Select|Wrap|Line Numbers
  1. int array[5];
  2.  
That is an array of 5 elements each of which is an int.

Expand|Select|Wrap|Line Numbers
  1. int array[];
  2.  
won't compile. You need to declare the number of elements.

Second, this array:
Expand|Select|Wrap|Line Numbers
  1. int array[5][10];
  2.  
is still an array of 5 elements. Each element is an array of 10 int.

Expand|Select|Wrap|Line Numbers
  1. int array[5][10][15];
  2.  
is still an array of 5 elements. Each element is an array of 10 elements where each element is an array of 15 int.


Expand|Select|Wrap|Line Numbers
  1. int array[][10];
  2.  
won't compile. You need to declare the number of elements.

Third, the name of an array is the address of element 0
Expand|Select|Wrap|Line Numbers
  1. int array[5];
  2.  
Here array is the address of array[0]. Since array[0] is an int, array is the address of an int. You can assign the name array to an int*.

Expand|Select|Wrap|Line Numbers
  1. int array[5][10];
  2.  
Here array is the address of array[0]. Since array[0] is an array of 10 int, array is the address of an array of 10 int. You can assign the name array to a pointer to an array of 10 int:
Expand|Select|Wrap|Line Numbers
  1. int array[5][10];
  2.  
  3. int (*ptr)[10] = array;
  4.  
Fourth, when the number of elements is not known at compile time, you create the array dynamically:

Expand|Select|Wrap|Line Numbers
  1. int* array = new int[value];
  2. int (*ptr)[10] = new int[value][10];
  3. int (*ptr)[10][15] = new int[value][10][15];
  4.  
In each case value is the number of elements. Any other brackets only describe the elements.

Using an int** for an array of arrays is incorrect and produces wrong answers using pointer arithmetic. The compiler knows this so it won't compile this code:

Expand|Select|Wrap|Line Numbers
  1. int** ptr = new int[value][10];    //ERROR
  2.  
new returns the address of an array of 10 int and that isn't the same as an int**.

Likewise:
Expand|Select|Wrap|Line Numbers
  1. int*** ptr = new int[value][10][15];    //ERROR
  2.  
new returns the address of an array of 10 elements where each element is an array of 15 int and that isn't the same as an int***.

With the above in mind this array:
Expand|Select|Wrap|Line Numbers
  1. int array[10] = {0,1,2,3,4,5,6,7,8,9};
  2.  
has a memory layout of

0 1 2 3 4 5 6 7 8 9

Wheras this array:
Expand|Select|Wrap|Line Numbers
  1. int array[5][2] = {0,1,2,3,4,5,6,7,8,9};
  2.  
has a memory layout of

0 1 2 3 4 5 6 7 8 9

Kinda the same, right?

So if your disc file contains

0 1 2 3 4 5 6 7 8 9

Does it make a difference wheher you read into a one-dimensional array or a two-dimensional array? No.

Therefore, when you do your read use the address of array[0][0] and read as though you have a
one-dimensional array and the values will be in the correct locations.
Feb 10 '08 #2
Probably your array definition has something top do with the C2440.

The C2664 is caused by a mismatch in the type of the third argument versus what you supplied. It looks like the third argument needs to be an int and you supplied an int*

I can't tell since you didn't post the definitions of your variables or your function prototype.

You mioght read this on arrays:

Thanks for the reply. I am still working on it. Here is the entire code.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MSIZE 81
void separate (char[], char[], int);/*function prototype*/
int main()
{
char date [MSIZE];
char tempmonth[MSIZE];
int tempday;
printf("\nEnter a month and a day. (Ex. June 14)\n");
gets_s(date);
printf("You entered: %s\n", date);

char *pttempmonthaddr;
int *pttempdayaddr;

pttempmonthaddr = &tempmonth;
pttempdayaddr = &tempday;

separate(date, pttempmonthaddr, pttempdayaddr);/*function call*/
printf("\nThe month entered is %s and day entered is %f.\n", *pttempmonthaddr, *pttempdayaddr);
return 0;
}
void separate(char *strin, char *strout, int *iout) /*function header*/
{
iout = 0;

while(*strin != '/0' && *strin != ' ')
*strout++ = *strin++;
*strout = '\0';
while (*strin != '\0' && *strin != ' ')
*strin++;

if(*strin != '\0')
*iout = atoi(strin);
}
Feb 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: OZ | last post by:
Hi, I am new C++ and need a little help with a public domain program that is suppose to perform a byte swap. I am receiving the following error messages during the compile process with Microsoft...
2
by: AK | last post by:
Hi, I have a Windows Forms .NET application - I'm trying to display a splash screen. I've checked out the online suggestion : http://support.microsoft.com/default.aspx?scid=kb;en-us;186459 I...
2
by: michael.rygh | last post by:
This is just one of the sources for a project that deals with a library. I am having problems, here is the errors. all these.. i belive it has something to do with it needs a subscript? but i'm...
1
by: KevinGPO | last post by:
My application was developed under Visual C++ 6.0, ATL, MFC & PlatformSDK Feb2003 (the last VC6 compatible version). I am wondering if PlatformSDK Feb2003 is compatible with Visual Studio.NET...
8
by: Ishu | last post by:
Hi, Can some one help on avoiding the following situation: The following code wont compile: template<class T> void MyClass::TestCode() {
1
by: cecille | last post by:
I have a C++ program that is giving me a CString type of data. But I have a C# DLL that accepts a String input in its argument. I need to access that C# dll that accepts a String parameter in...
2
by: teddybyte | last post by:
my script below is: #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, ...
0
by: alfie27 | last post by:
Hi, I am getting 2 errors when i try to run my program. This is my first time using the struct feature so i'm not sure how to correct my errors. Any help will be greatly appreciated. Here are the...
3
by: entice | last post by:
When I am compiling in visual c++ 2008 express edition I am receiving these two errors main.cpp(224) : error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR ' to 'const char *' Types...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.