C Programming <stdio.h>

Discussion in 'Mac Programming' started by cybrscot, Feb 16, 2011.

  1. cybrscot macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia
    #1
    Just curious, so far I've used the <stdio.h> header for everything. Will I ever use anything else? If you were to break it down, what % of programming is the <stdio.h> header? 90%? 50%

    Just wondering how common this one is, and if others are just not as useful or for very specific purposes.

    Thanks
    Scott
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    You need this file for I/O (Input/Output). If you care to, you can look at it... it should be in /usr/include. Explaining the specifics might not be that helpful if you haven't used your own .h files yet. At a very high level, these files are used to define function prototypes (since you haven't used functions, what a function prototype is won't really make sense), constants using #define (don't think you've covered this yet, either), typedefs (probably not yet), structs (don't think you've seen them), and assorted other pieces of data you'll need to make use of a standard library. Basically, someone else wrote some code. You may or may not have access to the source code, but you do have a compiled library. They have provided you with a header file that will act as a guide for what functions are available (to help both you and the compiler) and what datatypes will be used when interacting with the library.

    A lot of programs make use of file and console I/O, so a lot of programs will use this file. I don't think anyone could say a percentage, but it's much closer to 100% than 0% or 50%.

    -Lee
     
  3. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #3
    Any of the following 'Standard C' libraries are likely to be referenced sometime within your textbooks.

    <assert.h>
    <ctype.h>
    <errno.h>
    <float.h>
    <limits.h>
    <math.h>
    <setjmp.h>
    <signal.h>
    <stdlib.h>
    <stddef.h>
    <stdarg.h>
    <stdio.h>
    <string.h>
    <time.h>

    And these not quite as much in the United States.

    <locale.h>
    <wchar.h>
    <wctype.h>
     
  4. cybrscot thread starter macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia
    #4
    Forgive me for this, because I don't have a teacher. I thought the "C library" was a single all encompassing "library" of everything of use related to C programming? Are you saying that each header you mentioned above, actually represents a "different and unique" library within C? And each library has different functions, etc?
     
  5. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #5
    This will become more clear to you by the time you get to chapter 9 and start writing your own functions. Not all code needs to be in a single function main or a single *.c file.

    Read: http://en.wikipedia.org/wiki/C_standard_library

    One library, several files and functions.

    B
     
  6. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #6
    Lloyddean was being a bit loose with the language here. That list is a list of header files included in the 1 standard C library.
     

Share This Page