Thread: Error

  1. #1
    Unregistered
    Guest

    Exclamation Error

    can any1 help me with this error

    [C++ Error] project2.cpp(258): E2034 Cannot convert 'char *' to 'char'


    cheers

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    [C++ Error] project2.cpp(258): E2034 Cannot convert 'char *' to 'char'
    Looks like it should be in the c++ board for a start.
    Cannot convert a pointer to char to char.
    Show us the line with the error.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Unregistered
    Guest
    test=records[i].surname ;

    where test is declared as a char

    and records is the array

    and i am doin C not C++

    thnx

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    test=records[i].surname ;

    where test is declared as a char

    and records is the array

    and i am doin C not C++

    thnx
    Then don't use a ".CPP" file. Use a ".c" file. Post what 'test' is and what the structure looks like.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >test=records[i].surname ;

    If test is of type char and surname of type char *, then the error will occur.

    To make things sure, show us the type of variable records.

  6. #6
    Unregistered
    Guest
    struct student
    {
    char surname[40];
    int mark1;
    int late1;
    int mark2;
    int late2;
    int mark3;
    int late3;
    char grade[1];
    };
    struct student records[MAX];


    there is the structure of the array

    and test is declared as

    char test[20];

    thnx

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    So surname is of type char and 40 chars long and test is of type char and 20 chars long. That's not correct to assign them to eachother.

    You could solve this by using strncpy.

    #include <string.h>
    char *strncpy(char * restrict s1, const char * restrict s2, size_t n);

    In your case you could do:

    strncpy (test, records[i].surname, 20);

  8. #8
    Unregistered
    Guest
    cheers mate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM