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 8876889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:19:45+00:00 2026-06-14T19:19:45+00:00

This code converts a vector(argv) to a string, and prints it. However, if the

  • 0

This code converts a vector(argv) to a string, and prints it. However, if the vect2str is called from a library(my_vect2str), it gives a warning:

warning: passing argument 1 of ‘puts’ makes pointer from integer without a cast

And segfaults when ran. The function vect2str here is the exact same as the one in the library(my_vect2str). The library was compiled on the same computer.

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

#include "../lib/my.h"

char *vect2str(char **str) {

if (str == NULL)
    return NULL;
if (*str == NULL)
    return NULL;

int num = 0;
char * a;

int i;
for(i = 0; str[i] != '\0'; )
    num += strlen(str[i++]);

num += i;
a = (char *) xmalloc(num * sizeof(char));

//Make new string
char space = ' ';
char *end = "";

int j;
for(j = 0; str[j] != NULL; j++) {
    strcat(a, str[j]);
    strcat(a, &space);
    }
strcat(a, end);
return a;
}

int main(int argc, char **argv) {

puts(vect2str(argv));

//This does not work
//puts(my_vect2str(argv));
}
  • 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-06-14T19:19:46+00:00Added an answer on June 14, 2026 at 7:19 pm

    It compiles fine on cygwin and puts receives a char pointer alright.
    The problem I saw is that you are doing a strcat with a pointer to a single character.

    strcat(a, &space);
    

    The way strcat works is by copying from one string to another until it finds a terminating null character (‘\0’), if you don’t supply a string with one, strange things can happen, change it for this:

    strcat(a, " ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is arnorhs' code, which converts a date & time into human timing, such
This code - Convert.ToDecimal(28.9100000000000000).ToString(c) will convert a string containing a decimal value to a
I have written this code to convert string in such format 0(532) 222 22
I cannot figure out how to convert this code from C# to VB.net. It
This code gives me this error:Cannot implicitly convert type ArrayList[] to ArrayList[][] at this
I am using this code for on android just trying to convert string to
I am learning the boost::lambda library and for that I wrote this sample code
This program reads strings of numbers from a txt file, converts them to integers,
i am testing out this code which reads stdin and stores it in vector
Considering this code: std::vector<myObject*> veryLargeArray; for (int i = 0; i < veryLargeArray.size(); ++i)

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.