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

  • Home
  • SEARCH
  • 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 636717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:32:44+00:00 2026-05-13T20:32:44+00:00

my problem is in convert a char to string i have to pass to

  • 0

my problem is in convert a char to string
i have to pass to strcat() a char to append to a string, how can i do?
thanks!

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

char *asd(char* in, char *out){
    while(*in){
        strcat(out, *in); // <-- err arg 2 makes pointer from integer without a cast
        *in++;
    }
    return out;
}

int main(){
    char st[] = "text";
    char ok[200];
    asd(st, ok);
    printf("%s", ok);
    return 0;
}
  • 1 1 Answer
  • 1 View
  • 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-13T20:32:44+00:00Added an answer on May 13, 2026 at 8:32 pm

    Since ok is pointing to an uninitialized array of characters, it’ll all be garbage values, so where the concatenation (by strcat) will start is unknown. Also strcat takes a C-string (i.e. an array of characters which is terminated by a ‘\0’ character). Giving char a[200] = "" will give you a[0] = ‘\0’, then a[1] to a[199] set to 0.

    Edit: (added the corrected version of the code)

    #include <stdio.h>
    #include <string.h>
    
    char *asd(char* in, char *out)
    {
    
    /*
        It is incorrect to pass `*in` since it'll give only the character pointed to 
        by `in`; passing `in` will give the starting address of the array to strcat
     */
    
        strcat(out, in);
        return out;
    }
    
    int main(){
        char st[] = "text";
        char ok[200] = "somevalue"; /* 's', 'o', 'm', 'e', 'v', 'a', 'l', 'u', 'e', '\0' */
        asd(st, ok);
        printf("%s", ok);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem I need to convert char [] to String, hexadecimal format
My problem is, when I want to convert (result[i].JobOrder) to int.I have a string
I have method to covert character to haxa like private static String convert(char str)
I have a function to convert integer to string .The function is char *
I have a problem with wchar_t* to char* conversion. I'm getting a wchar_t* string
I have problem i need to convert from my Array structure to std::vector<int> ...
My problem is the following. I try to convert a string into double. In
I have faced a problem in Qt with error: cannot convert parameter 1 from
Possible Duplicate: C++ std::string conversion problem on Windows How to convert std::string to LPCSTR?
I'm having a problem with some for nested loops that I have to convert

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.