Thread: Newb Question - Cant convert Char[41] to Char

  1. #1
    Registered User
    Join Date
    Aug 2004

    Question Newb Question - Cant convert Char[41] to Char

    Hi All,

    I am new to this forum and to C++ programming. But still I have managed my program to error .

    Can someone tell me what is wrong with this code?!

    void main()
    	char User[UserMaxLength];
    	User = get_user();
    	printf("%s@!localhost [#]", User);
    char get_user()
    	char Temp[UserMaxLength];
    	scanf("Gebruikersnaam: %s", &Temp);
    	return Temp;
    The error I get is:
    C:\Program Files\Microsoft Visual Studio\MyProjects\Kernel\KK006b\KK006b.cpp(16) : error C2440: '=' : cannot convert from 'char' to 'char [41]'
            There are no conversions to array types, although there are conversions to references or pointers to arrays
    C:\Program Files\Microsoft Visual Studio\MyProjects\Kernel\KK006b\KK006b.cpp(31) : error C2440: 'return' : cannot convert from 'char [41]' to 'char'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Any help would be greatly appreciated


  2. #2
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Your return type is char. You are trying to return an array. the types dont' match so your getting an error. You want to return a pointer to the array.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    As a start, use "int main()" not "void main()". If you need an explanation, have a look at the FAQ.

    You cannot assign an array this way. For simplicity, I would suggest passing the array you need your data in to your get_user function and removing the temp variable.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  2. Fixing Errors
    By brietje698 in forum Networking/Device Communication
    Replies: 9
    Last Post: 12-10-2007, 11:17 PM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Searching a linked list for char
    By spentdome in forum C Programming
    Replies: 3
    Last Post: 05-22-2002, 11:11 AM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM