Printf to display chars

This is a discussion on Printf to display chars within the C++ Programming forums, part of the General Programming Boards category; I need to use printf to display a string (2D), one char at a time. This DOESN'T work: (why and ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    891

    Printf to display chars

    I need to use printf to display a string (2D), one char at a time. This DOESN'T work: (why and what will) (NOTE: the pump is just part of the program I'm making. Ignore.)

    PHP Code:
    #include "stdafx.h"
    #define _clrscr
    #include <monkey.h>
    //12x30

    char stuff[7][28]   =  {" _________________________ ",
                            
    "|   | |         |         |",
                            
    "|   | |  _____  |         |",
                            
    "|   | | |     | |         |",
                            
    "|   | |_|_____| |         |",
                            
    "|   |           |         |",
                            
    "|___|___________|_________|"};

    void display();

    int main(int argccharargv[])
    {
        
    //PUMP
        
    while(1)
        {
        
    display();
        
    getch();
        
    clrscr();
        }
        return 
    0;
    }

    void display()
    {
        for(
    int loop2 0loop2 7loop2++)
        {
        for(
    int loop1 0loop1 28loop1++)
        {
            
    chardisplayer = new char [1];
            
    displayer[0] = stuff[loop2][loop1];
            
    printf(displayer);
            if(
    loop1 == 27)
                
    printf("\n");
        }
        }

    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You could just do -

    Code:
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    string stuff   =  " _________________________ \n"
                            "|   | |         |         |\n"
                            "|   | |  _____  |         |\n"
                            "|   | | |     | |         |\n"
                            "|   | |_|_____| |         |\n"
                            "|   |           |         |\n"
                            "|___|___________|_________|\n";
    
    
    int main(int argc, char* argv[])
    {
        cout << stuff;
        return 0;
    }

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    891
    no cout allowed.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    OK -

    Code:
    void display()
    {
        for(int loop2 = 0; loop2 < 7; loop2++)
        {
        for(int loop1 = 0; loop1 < 28; loop1++)
        {
            char displayer;
            displayer = stuff[loop2][loop1];
            printf("%c",displayer);
            if(loop1 == 27)
                printf("\n");
        }
        }
    }

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    891
    Thanks.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 05:54 AM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 08:23 AM
  5. Replies: 4
    Last Post: 03-31-2003, 11:49 PM

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