Scanf and 2D arrays

This is a discussion on Scanf and 2D arrays within the C Programming forums, part of the General Programming Boards category; I'm trying to use scanf to store something in a 2D array and print it out, except im not sure ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    Scanf and 2D arrays

    I'm trying to use scanf to store something in a 2D array and print it out, except im not sure how to do this.. can any body help?

    for example:

    Input:

    ******
    *AAAA*
    *AAAA*
    ******

    output:


    ******
    *AAAA*
    *AAAA*
    ******

    Thank you
    Last edited by Killahkode; 09-27-2006 at 09:26 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Use fgets() rather than scanf() and read in each line individually into the array. If you don't want to deal with null characters, you can use getchar() in a loop incrementing the array index until you're at the end of the array.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf interactive program
    By rocketman03 in forum C Programming
    Replies: 9
    Last Post: 11-14-2008, 08:54 PM
  2. Large arrays, malloc, and strcmp
    By k2712 in forum C Programming
    Replies: 1
    Last Post: 09-24-2007, 08:22 PM
  3. 2D Dynamically allocated pointer arrays
    By Lionmane in forum C Programming
    Replies: 37
    Last Post: 06-11-2005, 10:39 PM
  4. Question about 2D arrays?
    By agentxx04 in forum C Programming
    Replies: 4
    Last Post: 12-16-2004, 11:31 AM
  5. input with 2D array and pointers
    By pxleyes in forum C Programming
    Replies: 13
    Last Post: 03-26-2004, 07:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21