char pointers: invalid conversion from 'char*' to 'char'?

invalid conversion from char* to char c++
invalid conversion from 'char' to 'char*' arduino
invalid conversion from char to const char*
invalid conversion from 'char*' to 'char*' (-fpermissive)
no known conversion from char to char
arduino invalid conversion from 'char' to 'char
invalid conversion from 'char to 'char fpermissive
c++ error invalid conversion from 'char*' to 'char' (-fpermissive)

I cut out all the unnecessary code so no one gets too bored with my question... So I cant get the char array to work! on the last few lines of

*whatname = guyname; 
*whatlastname = lastname;

I get an error saying invalid conversion from 'char*' to 'char'. Help would be much appreciated!

#include <stdio.h>
#include <ctype.h>
#include <string.h>

void getname(char *whatname, char *whatlastname);

int main()
{
    int option = 0;
    char guyname = 'x';
    char lastname = 'x';
    bool name_entered = false;

    do{
        printf("1. Enter name.\n");
        printf("2. Enter exam scores.\n");
        printf("3. Display average exam scores. \n");
        printf("4. Display summary. \n");
        printf("5. Quit. \n");
        scanf("%i", &option);

        if( option == 1 )
        {
            name_entered = true;
            getname(&guyname, &lastname);
        }
    else if( option == 4 )
    {
        {
            printf("%s %s based on your exam scores of \n",guyname, lastname);
        }
        else
        {
            printf("Please enter your name in option 1 and you exam scores in option 2 before continuing.\n");
        }
    }
        else if( option == 5 )
        {
            printf(" Come back with a better grade next time.");
            break;
        }
    }while (!(option >5 || option <1));
    return 0;
}

void getname (char *whatname, char *whatlastname)
{
    char guyname[32];
    char lastname[32];
    printf("Enter your first and last name : ");
    scanf("%s %s", &guyname, &lastname);

    guyname[0] = toupper( guyname[0] );
    int len = strlen(guyname);
    for(int i=1; i<len ; i++)
    {
        guyname[i] = tolower( guyname[i]);
    }

    lastname[0] = toupper( lastname[0] );
    int len1 = strlen(lastname);
    for(int k=1; k<len1; k++)
    {
        lastname[k]= tolower( lastname[k]);
    }

    printf("Your name is %s %s\n", guyname, lastname);
    *whatname = guyname;
    *whatlastname = lastname;
}

Dealing with char, char*, and char [] in C is a little confusing in the beginning.

Take a look at the following statements:

char str1[] = "abcd";
char const* str2 = "xy";
char* cp = str1;
char c = *cp;

In the first statement and the second statement are identical in their behavior. After the first statement is executed, str1 points to a location that contains 4 characters, in consecutive order. If you think of the memory locations for the string, you might see something like:

+---+---+---+---+
| a | b | c | d |
+---+---+---+---+

str1 points to the address where a is stored. There is a similar arrangement for storing the string "xyz" and str2 points to the address where x is stored.

In the third statement, you are creating cp that making it point where str1 is pointing. After that statement both cp and str1 point to the same string - "abcd".

*cp evaluates to the character that exists at the address that cp points to. In this case, it will be a.

In the fourth statement, you are assigning c to be a, the character that exists at the address pointed to by cp.

Now, if you try a statement

*cp = str2;

it is a compiler error. *cp simply dereferences the address of cp. You can put a char at that location, not str2, which is a char*.

You can execute

*cp = *str2;

After that, the objects in the memory that str1 and cp point to will look like:

+---+---+---+---+
| x | b | c | d |
+---+---+---+---+

If you want to copy the string from the address pointed to by str1 to the address pointed to by cp, you can use the standard library function strcpy.

strcpy(cp, str2);

You have to be careful about using strcpy because you have to have enough valid memory to copy to. In this particular example, if you tried

char str3[2];
strcpy(str3, cp);

you will get undefined behavior since there isn't enough memory in str3 to be able to copy "abcd".

Hope that made sense.

Here's a modified version of your code that should work:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

void getname(char *whatname, char *whatlastname);

int main()
{
    int option = 0;
    char guyname[32];
    char lastname[32];
    bool name_entered = false;

    do{
        printf("1. Enter name.\n");
        printf("2. Enter exam scores.\n");
        printf("3. Display average exam scores. \n");
        printf("4. Display summary. \n");
        printf("5. Quit. \n");
        scanf("%i", &option);

        if( option == 1 )
        {
            name_entered = true;
            getname(guyname, lastname);
        }
        else if( option == 5 )
        {
            printf(" Come back with a better grade next time.");
            break;
        }
    }while (!(option >5 || option <1));
    return 0;
}

void getname (char *whatname, char *whatlastname)
{
    char guyname[32];
    char lastname[32];
    printf("Enter your first and last name : ");
    scanf("%31s %31s", guyname, lastname);

    guyname[0] = toupper( guyname[0] );
    int len = strlen(guyname);
    for(int i=1; i<len ; i++)
    {
        guyname[i] = tolower( guyname[i]);
    }

    lastname[0] = toupper( lastname[0] );
    int len1 = strlen(lastname);
    for(int k=1; k<len1; k++)
    {
        lastname[k]= tolower( lastname[k]);
    }

    printf("Your name is %s %s\n", guyname, lastname);
    strcpy(whatname, guyname);
    strcpy(whatlastname,lastname);
}

C++: invalid conversion from char to char*?, *(t + i). t is of type char * . so t + i means char * + i which means "add the value of i to the pointer to make a new pointer". *(t + i) then dereferences that new pointer� Invalid conversion from const char* to char. 1 vote . 36 views. Problem: Hello Kodlogs, I am going through a problem for the last few minutes. I tried to solve it in


You have a pair of values in the main which are single characters.

You're passing in pointers to those characters, then dereferencing them (which gives you single characters again), then trying to assign character pointers to them. That definitely isn't going to work.

Even if you did,

whatname = guyname; 
whatlastname = lastname;

which would be type-correct, it wouldn't do what you seem to want, which is to change the values in the calling function. It would only change the values of the argument variables in the subroutine.

If you're trying to return two strings found in the subroutine, change the calling code's variables to:

char *guyname = "x";
char *lastname = "x";

and change the function arguments to

void getname (char **whatname, char **whatlastname)

Then your assignment will be type-correct, and will change the pointers in the calling function.

[Solved] 24:21: error: invalid conversion from 'char' to 'char , Hide Copy Code. void reverseit(char st[100]) This signature states, that reverseit accepts a 100 char long array, but you call it with a single char. char *guyname = "x"; char *lastname = "x"; and change the function arguments to. void getname (char **whatname, char **whatlastname) Then your assignment will be type-correct, and will change the pointers in the calling function.


There shouldn't be & in scanf of string.

invalid conversion from 'char' to 'char* - C++ Forum, out2[i] = sentence[i]; // error: invalid conversion from 'char' to 'char*' [-fpermissive] out2 is an array of pointers to char, so out2[i] has type char*. C++ is designed to be more type safe than C, therefore you cannot (automatically) convert from void* to another pointer type. Since your file is a .cpp, your compiler is expecting C++ code and, as previously mentioned, your call to malloc will not compile since your are assigning a char* to a void*.


lot of things wrong here. You need to think about where the two string are going to be stored.

You are trying to return variable on the stack of getname - even if you fix the C code that wont work.

a) getname needs to be getname(char**, char**)

b) whatname and whatLastname need to be char *

c) call getname with (&whatname &whatLastName)

d) strdup the strings in getname into the two params (*whatname,...)

How to resolve the error: "invalid conversion from int to int*", The “invalid conversion from into to int*” error is encountered when an integer pointer is assigned an integer value. Remember: pointers are used to store the � Take into account that pointers can be defined as. const char * const filename = "String Literal"; C++ invalid conversion from 'const char*' to 'char*' Arduino Uno.


first of all, using * on a pointer will dereference it (you did it on the last two lines) secondly, you are sending to the function a pointer to a single char, not an array of chars so if you will write to its memory you will write on some other variable's memory. What you should have done is declaring guysname and lastname as char arrays

char guysname[32];

and in your function just read your input directly into the parameters you recieve:

scanf("%s %s", whatname, whatlastname);

replace all instances of guysname and lastname for whatname and whatlastname. get rid of the last lines. If you want to keep the char arrays inside the function anyway, just use

strcpy(whatname,guysname)

and the same for the last name.

Why I'm getting this error: invalid conversion from 'const char*' to , A char can only store one character. and const char* data can store a pointer to a string. You can copy it with strcpy: const char* data = malloc� Running above program may generate a warning also “warning: deprecated conversion from string constant to ‘char*’”. This warning occurs because s is not a const pointer, but stores address of the read-only location.


Error " invalid conversion from 'char' to 'const char*' " in C++ , PROBLEM SOLVED Someone can explain me how to solve this error. Thank you very much. c++ pointers char string. 11th May 2020, 7:23 AM. Joita Vladut. Top Forums Programming Invalid conversion from char* to char # 1 Plum. Registered User. 1, 0. Join Date: Mar 2014. I'm using C so am limited to char pointers and


invalid conversion from 'char' to 'char*', &va is a pointer to it. I'm guessing this: Code: [Select]. display.print(&va); But it isn � Programming :: C++ Invalid Conversion From Const Char* To Char* Jul 9, 2010. I am having trouble with the following exception class. Code: /**Standard Exception


How to rectify invalid conversion from 'const char**' to 'char* const , So you have a pointer to an array of const C strings, or a const char pointer pointer with storage that is a collection of different char arrays.