3

This is/isn't homework...the printing of the list IS homework and that works great, the iscntrl() and Array stuff is 6 weeks from now stuff and giving me grief.

I want to create an array filled with the first 32 TLAs of the Ascii table so that when I print out a column / row chart of Decimal to Ascii code I can use iscntrl() to flag that it's an un-printable character. In its place I want to grab the next TLA in the array and print that instead of the non-graphical character.

I have the iscntrl() working fine. Just can't figure out the array thing. All the examples in the books I have and online want to demo grabbing input from the user and tossing it into the array. I want to give the array a list at the beginning in the code and pull from that.

Can someone either give me a good link for what I need or just tell me how to do the whole process?

I've got 32 three letter items and I need to populate the array and pull them out via a for loop.

Thanks.

2 Answers 2

4

You can declare an array like this, and pre-fill its values:

const char *ControlCharacterNames[] = {
    "NUL",
    "SOH",
    "STX",
    "ETX",
    // etc
};

Then, you can access ControlCharacterNames as an array in your code.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you SOOOO much! Now I won't be awake all night pulling my hair out.
3

http://publications.gbdirect.co.uk/c_book/chapter6/initialization.html, chapter "6.7.2. More initialization".

Long story short, you probably need something like

char *TLAs[] = { "TL1", "TL2", "TL3", "FYI", "WTH", /* ...and so on...*/ };

and then pull the one you need using it's index

printf(TLAs[3]); // print "FYI", the 4th TLA

Hope I understood your question right.

1 Comment

Okay, I need to start typing this stuff faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.