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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:50:56+00:00 2026-06-18T12:50:56+00:00

I have a character arraym char Input[200]; input as of now has the string

  • 0

I have a character arraym
char Input[200];

input as of now has the string “abc.txt”.

I have a method that strictly needs a const char *, how can I convert my input array into a const char *.

I tried casting it, and passing it, but upon using GDB, I feel like since the remaining 192 slots in input are filled with garbage(or are empty)its not being accepted by the function. When I pass the string literal “a.txt” to the function it works. so at this point I would like to extract the filled up elements from input array and convert it to a const char *.

I am taking input as a filename from a user, so I used a char array to store the input.

   int main()
    {
    char *name;

    char input[1024];
    strcpy(input, argv[1]);

    name = input;

    sys_open(input, "O_RDWR", 00700);


    }
  • 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-18T12:50:57+00:00Added an answer on June 18, 2026 at 12:50 pm

    You should be able to pass it directly. A char[] can be cast to a const char *, but not vice versa.

    The reason that you see all of the garbage in gdb is because arrays are not pre-initialized to contain anything, so you’re just seeing whatever garbage was in there before. As long as your string is null-terminated, it should be fine.

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

Sidebar

Related Questions

I have a method (C++) that returns a character and takes an array of
In my main file I have an array of character strings, char names[320][30], and
I have this character array char array[] = {1,2,3}; //FL, FH, Size and I
I have a large character array in the device global memory that is accessed
I have an object that works with arrays of smaller objects. I am now
At input i have some string : today snowing know , here i have
Here i have one string means character array. this array contains separator character also.
I have this simple problem that gets an input from the user using a
I have a char array buffer that I am using to store characters that
I have a datatype that's more or less a character array. Each space in

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.