Thread: multi dimensional string in C

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    8

    multi dimensional string in C

    Hello.
    I want to ask is there some way how to write multi dimensional string? I want to write/output this string.
    Code:
    char field[7][16]={"-----------------",
                           "|                       |",
                           "|                       |",
                           "|                       |",
                           "|                       |",
                           "|                       |",
                           "|                       |",
                           "|                       |"};
    Thanks for help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    It's just a for loop printing field[i]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    i dont know how exactly do it can you help me please?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Do you know what a for loop looks like?

    Do you know how to use printf("%s"
    - with a char array
    - with a char pointer
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    yeah but it doesnt work.. :/

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by smola14 View Post
    yeah but it doesnt work.. :/
    Yeah, but "it doesnt work" is not a good response.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Quote Originally Posted by smola14 View Post
    yeah but it doesnt work.. :/
    Post your best effort attempt, then we can tell you where you're going wrong.

    It's way too easy to claim "it doesn't work" without having actually done anything at all.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    sorry..i try to do in this way but its all in one line..in for it doesnt work or im doing it bad
    Code:
    char field[7][16]={"-----------------\n",
                           "|               |\n",
                           "|               |\n",
                           "|               |\n",
                           "|               |\n",
                           "|               |\n",
                           "|               |\n",
                           "|               |\n"};
        puts(field);

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Each of those strings is 20 characters wide, so how you're not getting notification by your compiler when you try to initialize that into a 16-character space I don't know.

    Also, for loops involve the word for, so that may be a good place to start looking in your notes/book.

  10. #10
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    thank you its working now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String-length of an multi-dimensional array
    By doxii in forum C Programming
    Replies: 15
    Last Post: 10-30-2008, 02:36 PM
  2. multi-dimensional arrays
    By shuo in forum C++ Programming
    Replies: 7
    Last Post: 06-17-2008, 10:22 PM
  3. multi-dimensional array
    By shuo in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2008, 01:03 AM
  4. multi-dimensional arrays
    By maple23 in forum C Programming
    Replies: 4
    Last Post: 05-31-2008, 01:58 AM
  5. Help with multi-dimensional string arrays
    By nsaP in forum C Programming
    Replies: 9
    Last Post: 12-13-2004, 08:17 PM

Tags for this Thread