i'm trying to design a c program that will help newcomers to the Internet understand certain abbreviations.I have 8 abbreviations such as AFAIK - as far as i know etc. I am storing the abbreviations in one array [][8],and the descriptions in another[][8] and initialising them. BUT, I don't know how to link the two arrays together. I think I have to copy one string to another, but not sure what the loop is. I haven't been taught pointers yet, but i know I need to use strcpy. Can someone please help?

Recommended Answers

All 2 Replies

Here is a small example on how to do it, you can easily mould it to your needs:

#include <iostream>
#include <cstring>

int main()
    char* digit[] = { "1", "2", "3", "4" } ;
    char* number[] = { "one", "two", "three", "four" } ;

    for( int i = 0; i < 4; ++i )
        std::cout << digit[i] << " is equivalent to " << number[i] << std::endl ;
    return 0 ;

The most basic way to keep them together is to do as ~s.o.s~ did by having them ordered the same, so that a given index into one array will correspond to the same index into the other array. If you're just starting in C, this is probably the best way to go for now...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.