Small Problem in C, Please Help.

This is a discussion on Small Problem in C, Please Help. within the C Programming forums, part of the General Programming Boards category; Hi, I'm new to C programming and I'd like to get better at it. I was just writing a basic ...

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

    Small Problem in C, Please Help.

    Hi, I'm new to C programming and I'd like to get better at it. I was just writing a basic grade program and I ran into this problem:

    When displaying printf text I want to display a percent sign but it won't let me. It would be great if someone helped me out with this problem. +Rep for helping a newb?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,255
    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
    	printf("%%\n");
    	return 0;
    }

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    For future "how do I use this function?" questions you might want to try a google search for "man <function name>" first. For example: http://www.google.com/search?q=man+printf
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    8
    Quote Originally Posted by bithub
    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
    	printf("%%\n");
    	return 0;
    }
    Wow, thanks for being so quick.. Another question; what purpose does this serve:

    Code:
    int main(int argc, char *argv[])
    does that have anything to do with the display of the %?

    Do these forums have +Rep? or another form of appreciation like that?

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,255
    Are you asking what the main function is, or what the parameters being passed to main are for? Either way, the answer is no, it has nothing to do with the printf() statement. I think your questions regarding the main function would be answered by just about any beginning C tutorial you can find on the net.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    The first argument passed to main() is the number of command-line arguments passed to the program. The second argument is a NULL-terminated array of strings representing those command-line arguments and the name of the program.

    If you ran your program like: myprogram foo bar
    Code:
    argc would be 3
    argv would be { "myprogram", "foo", "bar", NULL }
    If you understand what you're doing, you're not learning anything.

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    8
    Wow, thank you very much everyone, I will definitely be posting here again..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small Problem with double and integer adding?
    By Nathan the noob in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2009, 05:16 PM
  2. Visual C++ small problem
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 03-10-2009, 11:45 PM
  3. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 04:16 PM
  4. Help with a small problem (beginner)
    By piffo in forum C Programming
    Replies: 13
    Last Post: 09-29-2008, 05:37 PM
  5. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 04:23 AM

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