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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:02:27+00:00 2026-05-16T12:02:27+00:00

I am trying to pass an array of character strings (C style strings) to

  • 0

I am trying to pass an array of character strings (C style strings) to a function. However, I don’t want to place a maximum size on length of each string coming into the function, nor do I want to allocate the arrays dynamically. Here is the code I wrote first:

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

void fun(char *s[])
{
    printf("Entering Fun\n");
    printf("s[1]=%s\n",(char *)s[1]);
}

int main(void)
{
    char myStrings[2][12];

    strcpy(myStrings[0],"7/2/2010");
    strcpy(myStrings[1],"hello");
    fun(myStrings);

    return(0);
}

I got a seg fault when run and the following warning from the compiler:
stackov.c: In function ‘main’:
stackov.c:17: warning: passing argument 1 of ‘fun’ from incompatible pointer type
stackov.c:5: note: expected ‘char **’ but argument is of type ‘char (*)[12]’

However, when I change the main() to the following it works:

int main(void)
{
    char myStrings[2][12];
    char *newStrings[2];

    strcpy(myStrings[0],"7/2/2010");
    strcpy(myStrings[1],"hello");
    newStrings[0]=myStrings[0];
    newStrings[1]=myStrings[1];
    fun(newStrings);

    return(0);
}

Isn’t array[2][12] the same thing as an array of character pointers when it is passed to a function?

  • 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-16T12:02:28+00:00Added an answer on May 16, 2026 at 12:02 pm

    Try

    void fun(char s[][12]) { ...}

    Read also from the c-faq: My compiler complained when I passed a two-dimensional array to a function expecting a pointer to a pointer

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

Sidebar

Related Questions

I am trying to pass a member function within a class to a function
I am trying to pass array parameter to SQL commnd in C# like below,
Im trying to pass an array from javascript to java servlet using Jackson, how
I am trying to pass an array of a simple object to a web
I am trying to pass an array of values into an array of a
I'm trying to pass an array of ( varchar ) data into an Oracle
I am trying to pass an array of ints from C# to C++/CLI. Here's
I am trying to pass an array of interfaces from C# to C++/CLI. Here
I am trying to pass a nested array to an asp.net mvc controller like
I'm trying to pass my own array of objects: results[num_row] = {'title:\'' + title

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.