How to fix error C2440


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How to fix error C2440

  1. #1
    vivek Guest

    How to fix error C2440


    hi,
    I'm relatively new to this area. I was trying to compile the following program
    on microsoft VC++ 6.0



    #include<stdio.h>
    typedef struct {
    char firstname[32];
    char lastname[32];
    int studentID[10];
    }candidate;

    void main(void){
    candidate c1;
    c1.firstname="vivek";
    c1.lastname="roy";
    c1.studentID=1234567;
    printf(" the candidate's name is %s %s and his ID is %d",c1.firstname,c1.lastname,c1.studentID);
    }



    and i'm getting the following errors.




    --------------------Configuration: try - Win32 Debug--------------------
    Compiling...
    test.cpp
    D:\test.cpp(11) : error C2440: '=' : cannot convert from 'char [6]' to 'char
    [32]'
    There is no context in which this conversion is possible
    D:\test.cpp(12) : error C2440: '=' : cannot convert from 'char [4]' to 'char
    [32]'
    There is no context in which this conversion is possible
    D:\test.cpp(13) : error C2440: '=' : cannot convert from 'const int' to 'int
    [10]'
    There are no conversions to array types, although there are conversions
    to references or pointers to arrays
    Error executing cl.exe.

    test.obj - 3 error(s), 0 warning(s)



    how to fix this. please help
    thanx a lot

    vivek


  2. #2
    alan Guest

    Re: How to fix error C2440


    Vivek
    have a look at this link
    hope it helps
    http://www.cplusplus.com/doc/tutorial/tut3-2.html

    "vivek " <vivek400@yahoo.com> wrote:
    >
    >hi,
    >I'm relatively new to this area. I was trying to compile the following program
    >on microsoft VC++ 6.0
    >
    >
    >
    >#include<stdio.h>
    >typedef struct {
    > char firstname[32];
    > char lastname[32];
    > int studentID[10];
    >}candidate;
    >
    >void main(void){
    > candidate c1;
    > c1.firstname="vivek";
    > c1.lastname="roy";
    > c1.studentID=1234567;
    > printf(" the candidate's name is %s %s and his ID is %d",c1.firstname,c1.lastname,c1.studentID);
    >}
    >
    >
    >
    >and i'm getting the following errors.
    >
    >
    >
    >
    >--------------------Configuration: try - Win32 Debug--------------------
    >Compiling...
    >test.cpp
    >D:\test.cpp(11) : error C2440: '=' : cannot convert from 'char [6]' to 'char
    >[32]'
    > There is no context in which this conversion is possible
    >D:\test.cpp(12) : error C2440: '=' : cannot convert from 'char [4]' to 'char
    >[32]'
    > There is no context in which this conversion is possible
    >D:\test.cpp(13) : error C2440: '=' : cannot convert from 'const int' to

    'int
    >[10]'
    > There are no conversions to array types, although there are conversions
    >to references or pointers to arrays
    >Error executing cl.exe.
    >
    >test.obj - 3 error(s), 0 warning(s)
    >
    >
    >
    >how to fix this. please help
    >thanx a lot
    >
    >vivek
    >



  3. #3
    jonnin Guest

    Re: How to fix error C2440



    You can't use = with arrays. Use the stl string class, or do the assign in
    a loop, or include <string.h>
    strcpy(destination,source); to do the assign.
    actually, memcpy is probably best for this in C, stl string for C++.







    "vivek " <vivek400@yahoo.com> wrote:
    >
    >hi,
    >I'm relatively new to this area. I was trying to compile the following program
    >on microsoft VC++ 6.0
    >
    >
    >
    >#include<stdio.h>
    >typedef struct {
    > char firstname[32];
    > char lastname[32];
    > int studentID[10];
    >}candidate;
    >
    >void main(void){
    > candidate c1;
    > c1.firstname="vivek";
    > c1.lastname="roy";
    > c1.studentID=1234567;
    > printf(" the candidate's name is %s %s and his ID is %d",c1.firstname,c1.lastname,c1.studentID);
    >}
    >
    >
    >
    >and i'm getting the following errors.
    >
    >
    >
    >
    >--------------------Configuration: try - Win32 Debug--------------------
    >Compiling...
    >test.cpp
    >D:\test.cpp(11) : error C2440: '=' : cannot convert from 'char [6]' to 'char
    >[32]'
    > There is no context in which this conversion is possible
    >D:\test.cpp(12) : error C2440: '=' : cannot convert from 'char [4]' to 'char
    >[32]'
    > There is no context in which this conversion is possible
    >D:\test.cpp(13) : error C2440: '=' : cannot convert from 'const int' to

    'int
    >[10]'
    > There are no conversions to array types, although there are conversions
    >to references or pointers to arrays
    >Error executing cl.exe.
    >
    >test.obj - 3 error(s), 0 warning(s)
    >
    >
    >
    >how to fix this. please help
    >thanx a lot
    >
    >vivek
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center