Thread: Calling a bunch of text by a keyword

  1. #1
    Registered User jsmithy's Avatar
    Join Date
    May 2010
    Posts
    2

    Question Calling a bunch of text by a keyword

    Hey guys,
    I just started programming with C and I was wondering if its possible to call a bunch of text instead of repeating the printf commands.
    For example I want to display the following banner (which reads "data storage system" made up of the # characters sorry it looks all messy lol) different areas of the program, but i dont want to keep copying and pasting coz it takes up so many lines.... is there a way to store it and give it a name then call the name when ever i need the banner to be displayed.
    Sorry if it doesn't make any sense just new to this programming business lol
    Thanks in advance
    Code:
    		printf("*******************************************************************************\n");
    		printf("*                                                                             *\n");
    		printf("* ##       #           ##  #                           ##          #          *\n");
    		printf("* # #  ## ###  ##     #   ### ### ###  ## ### ###     #   # #  ## ### ### ### *\n");
    		printf("* # # # #  #  # #      #   #  # # #   # # # # ##       #  ###  #   #  ##  ### *\n");
    		printf("* # # ###  ## ###       #  ## ### #   ###  ## ###       #   # ##   ## ### # # *\n");
    		printf("* ##                  ##                  ###         ##  ###                 *\n");
    		printf("*                                                                             *\n");
    		printf("*******************************************************************************\n");
    Last edited by Salem; 05-24-2010 at 08:50 AM. Reason: Added [code][/code] tags - learn to use them yourself

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    You could use a character array or a pointer to store the string, then pass the array/pointer to printf to print.

    The main differences that you need to know about, are:
    1) Arrays are a lot easier for a beginner.
    2) If you assign a string literal to a pointer then the string is read only.

    If you don't want to modify the string you could use either a pointer to the string or an array, considering their relative ease of use I'd go with arrays.

    There are a bunch of array tutorials around the net, just google "C Arrays" and you should strike gold.

    It's also possible to do this using #define directives, but that's poor programming practice, so I'd recommend against that.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    "calling a bunch of text by a keywords" sounds very much like "calling a function". Wrap it all up in a function, call it when you need it.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User jsmithy's Avatar
    Join Date
    May 2010
    Posts
    2
    WOW thanks for the rapid responses guys, i think i might try out Quzah's method.
    Cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-05-2010, 02:43 PM
  2. RichEditCtrl & unicode formatted text
    By ddonate in forum Windows Programming
    Replies: 0
    Last Post: 03-26-2010, 10:50 AM
  3. Need Help in Compiling errors
    By sick in forum C Programming
    Replies: 2
    Last Post: 01-21-2010, 03:26 AM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM