Quick question

This is a discussion on Quick question within the C Programming forums, part of the General Programming Boards category; Ok someone new here, when you get code like printf("%s") not sure if that is how it goes but what/why ...

  1. #1
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Quick question

    Ok someone new here, when you get code like

    printf("%s")

    not sure if that is how it goes but what/why does that
    "%whatever" do??
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    It's a special format string. %s means "Print a string".
    printf("%s"); alone won't do much (will probably crash).

    Look at this example for its use: (%d = integer)
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
       char Name[] = "David";
       int Age = 19;
    
       printf("Hello %s, are you %d years old?", Name, Age);
       getch();
       return 0;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Alright thanks Magos I will try that for a bit and something a bit off topic can anyone reccomend a good C book for reference that would have all of these simple questions answered somewhere in it?
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    No - but if you get the online help that comes with most big comercial compilers (even Borland's free downloads!), you can do searches, and it'll have good reference sections. With this for example, it explains the basics, and then it has a table of all the symbols to use in the format string. It's excellent.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

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