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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:56:44+00:00 2026-06-17T13:56:44+00:00

Please have a look at this program #include<stdio.h> #include<string.h> typedef struct hs_ims_msrp_authority { int

  • 0

Please have a look at this program

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

typedef struct hs_ims_msrp_authority
{
   int     host_type;
   char    buf[50];
   int     port;
}hs_i;

int main()
{
 char dom[50];
 int i = 10, j = 20;
 strcpy(dom, "ine");
 fun((hs_i){i, dom, j});   // doesnt work
 fun((hs_i){i, "dom", j}); // this works
}

int fun(hs_i c)
{
 printf("%d %s %d\n", c.host_type, c.buf, c.port);
}

In call to fun function in main; how come function call work when string literal (“dom”) is passed where as when array variable (dom) is passed it doesnt work?

To make variable work should it be typecasted in a specific way? or is there any other way?

  • 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-17T13:56:45+00:00Added an answer on June 17, 2026 at 1:56 pm

    The presence of the compound literal is distracting and the cause of the error is the attempt to initialize a char[] with another char[] array. The following is illegal:

    char dom[50] = "test";
    char dom1[50] = dom;  /* Line 16, the cause of the error. */
    

    and clang reports the following error:

    main.c:16:10: error: array initializer must be an initializer list or string literal

    Point 14 in section 6.7.8 Initialization of the C99 standard states:

    An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.

    So the call with the string literal "dom" is permitted as it is legal to initialize an array with a string literal, but the call with the char[] is not permitted.

    Possible solutions:

    • change the type of buf to be a const char*
    • wrap the buf member in a struct which would enable it to be copied. For example:

      struct char_array
      {
          char data[50];
      };
      
      typedef struct hs_ims_msrp_authority
      {
          int     host_type;
          struct char_array buf;
          int     port;
      } hs_i;
      
      struct char_array dom = { "ine" };
      int i = 10, j = 20;
      
      fun((hs_i){i, dom, j});
      fun((hs_i){i, { "dom" }, j});
            /* Note ^       ^ */
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look on this code: #include <unistd.h> #include <stdlib.h> #include <stdio.h> int
I have written a simple Hello World program. #include <stdio.h> int main() { printf(Hello
Please have a look at this form that I am trying to design with
Please have a look at this page www.pixeli.ca/issue. I have begun making a page
Please have a look at this demo page that I cooked up a while
Please have a look at this validation array in my cakephp app for model
Please have a look at the following machine code ‎0111001101110100011100100110010101110011011100110110010101100100 This means something. I
I have a problem with internet explorer 6 and 7, please look this example
can someone take a look at this please http://jsfiddle.net/bloodygeese/ecscY/56/ it looks like I have
Please have a look at the following code: $(#saveButton).click(function(){ $this = $(#tableData).find(input:checked).parent().parent(); tea =

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.