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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:19:24+00:00 2026-05-15T11:19:24+00:00

Hey everyone, I’m basically new to programming. I’ve decided to try and get started

  • 0

Hey everyone, I’m basically new to programming. I’ve decided to try and get started with C (not C++ or C#) and so far I’ve been doing pretty well. I managed to get far as two-dimensional arrays before I started to falter. While I think I broadly understand 2D integer arrays, I certainly don’t understand 3D string arrays.

I’m learning by taking the techniques and applying them in an actual program I’ve created, an exchange rate “calculator” that basically takes asks the user to select a base currency then prints its value in USD. There’s no maths involved, I simply googled stuff like EUR/USD and set the values manually in the array which I discuss below.

But here’s where I’m getting stuck. I figure the best way to learn multi-dimensional arrays is to practically apply the theory, so here’s what I’ve typed so far (I’ve omitted the other functions of my program (including the code which calls this function) for brevity):

 char currencies[5][3][4] = {
    {'1','2','3','4','5'},
    {'GBP','EUR','JPY','CAD','AUD'},
    {'1.5','1.23','0.11','0.96','0.87'}
};

int point, symbol, value;

displayarraycontents()
{
    for(point=1;point<5;point++){
        for(symbol=1;symbol<5;symbol++){
            for(value=1;symbol<5;symbol++)
                printf("%s ", currencies[point][symbol][value]);
            printf("\n");
        }}

}

Because C doesn’t feature a string data type, building string arrays completely messes with my head.

Why currencies[5][3][4]? Because I’m storing a total of 5 currencies, each marked by a 3-letter symbol (eg EUR, CAD), which have a value of up to 4 digits, including the decimal point.

I’m trying to display this list:

1 GBP 1.5
2 EUR 1.23
3 JPY 0.11
4 CAD 0.96
5 AUD 0.87

When I click build, the line where I specify the values in the array is highlighted with several instances of this warning:

warning: overflow in implicit constant conversion

…and the line where I print the contents of the array is highlighted with this warning:

warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

Upon running the code, the rest of the program works fine except this function, which produces a “segmentation error” or somesuch.

Could somebody give me a hand here? Any help would be greatly appreciated, as well as any links to simple C 2D/3D string array initialisation tutorials! (my two books, the K&R and Teach Yourself C only provide vague examples that aren’t relevant)

Thanks in advance!
-Ryan

EDIT: updated code using struct:

struct currency {
    char symbol[4];
    float value[5];
};


void displayarraycontents(){

        int index;

        struct currency currencies[] {
            {"GBP", 1.50},
            {"EUR", 1.23},
            {"JPY", 0.11},
            {"CAD", 0.96},
            {"AUD", 0.87},};

}

I get the following errors:
main.c:99: error: nested functions are disabled, use -fnested-functions to re-enable
main.c:99: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute‘ before ‘{‘ token
main.c:100: error: expected ‘;’ before ‘}’ token
main.c:100: error: expected expression before ‘,’ token

In the actual code window itself, every symbol is flagged as an “unexpected token”.

  • 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-15T11:19:24+00:00Added an answer on May 15, 2026 at 11:19 am

    In this case, you don’t actually want a 3D array. In fact, since you have a table of values, all you need is a 1D array.

    The tricky part is that each element of the array needs to store two things: the currency symbol, and the associated exchange rate. C has a way of building a type that stores two things – it’s the struct mechanism. We can define a struct to hold a single currency:

    struct currency {
        char symbol[4];
        char value[5];
    };
    

    (Note that this does not create a variable; it creates a type. struct currency is analagous to char, except that we defined the meaning of the former ourselves).

    …and we can now create an array of 5 of these:

    struct currency currencies[5] = { 
        {"GBP", "1.5" },
        {"EUR", "1.23" },
        {"JPY", "0.11" },
        {"CAD", "0.96" },
        {"AUD", "0.87" } };
    

    To iterate over them and print them out, the code would look like:

    void displayarraycontents(void)
    {
        int point;
    
        for(point = 0; point < 5; point++)
        {
            printf("%d %s %s\n", point + 1, currencies[point].symbol, currencies[point].value);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 453k
  • Answers 453k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to specify the message type: $email->getValidator('emailAddress')->setMessage("'%value%' is not… May 15, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer Ensure that AllowDragDrop is set to true. Implement handlers for… May 15, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer The latter: build a model with a one to one… May 15, 2026 at 9:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.