Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:38:16+00:00 2026-05-17T17:38:16+00:00

My code, when compiled, returns the error invalid conversion from ‘char*’ to ‘char’ ,

  • 0

My code, when compiled, returns the error invalid conversion from ‘char*’ to ‘char’, and identifies the second last line, return char32 as the problem. I’ve searched the Internet and this site and haven’t found anything that has helped. I’ve found the error goes away and the code compiles if I replace the problem line with return *char32, but I’m not entirely sure why this should be the case. I understand that this is pointer notation, but I’m unsure how they apply to this situation. Also, when I do this and attempt to print *char32 to the terminal, nothing happens, indicating that *char32 in empty. I’ve also verified that there is indeed a line being read in from the file some file.

Update 1: I am attempting to return a full array from parse().

Update 2: I realise I didn’t state my goal for this code. I am attempting to read the first line from the some file, pass it to parse() and have the first 32 characters indexed into the array char32, which will then be passed back to main(). Sorry for the confusion.

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

char parse(string line), char32[32];

int main()
{
    string line;
    ifstream vgv;
    vgv.open("some file");

    getline(vgv, line);
    cout << char32;

    return 0;
}

char parse(string line)
{
    int size = line.size();
    for (int count1 = 0; count1 < 32; count1 ++)
    {
        char32[count1] = line[count1];
    }

    return char32;
}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:38:16+00:00Added an answer on May 17, 2026 at 5:38 pm

    There are many problems here.

    If you really want to return a single character that should be

    return char32[0];
    

    or whichever character you want, by index. This is the same as *char32 by the way. An array variable can be treated as a pointer to the first array in the element, if no index is used. Although since char32 is a global it’s not really adding any value above the function returning void – the caller can just access char32 directly. If you want to output the results using cout it would be better to return a new string from parse.

    You should stop the loop in parse when you reach min(size, 32), or you will overrun the input string in line with undefined results (bad, typically). it would be a good idea to allow space for a null terminator here – again using string would just obviate this.

    Magic numbers are evil. Use this instead of the hard-coded 32:

    const size_t MAX_LENGTH(32);
    

    If all parse does is byte-by-byte copy, you could use std::copy but I suspect this is a prototype for a real parser you plan to build once interface issues are resolved. I think you are missing a call to char myresult = parse(line); before you output char32 to cout by the way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know what is code compiled unit in .net. It s located
I have a C++ assembly with both managed and umanaged code compiled to a
We get an abort when a C++ exception is thrown when running code compiled
I thought .Net code gets compiled into MSIL, so I always wondered how do
My application runs on a pSOS operating system. The code is compiled with Diab
How would one go about loading compiled C code at run time, and then
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
I installed the wxWidgets source code, compiled it and am linking the libraries thus
Just wondering if a .NET app can be compiled down to native machine code
Since XAML gets compiled, there should be no difference in execution of code like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.