wiki:ResumedC

Version 1 (modified by Thanatermesis, 16 years ago) ( diff )

--

Comments

The comments are very important for yourself basically, you need to comment all your functions and declarations, and specially you need to comment your variables in order to know *what* exactly they are, and also for know possible special things of these variables

It is recommended to learn how works doxygen (5 minutes reading a howto in google, it is very basic) so that you can know special techniques to comment your source code that then you can build documentation of your API/source directly from these comments

The special things that you need to have in mind when you code is: clarity of code, simplicity, and summary

Basic Things

To declare a string in a variable, you need to use strcpy, so

   name = "Me";   /* Illegal */
   strcpy (name, "Me");    /* Legal */

When you assign a single character you need to enclose it in single-quotes ', if you want to assign a string (with the end-of-string (NULL) char included), you need to use double-quotes ".

A good way to remove the newline value from variables (when you use a input-line entry system) is by simply set the end-of-string (NULL) value to the newline place, like:

   fgets(first, sizeof(first), stdin);
   first[strlen(first)-1] = '\0';

Remember that a string contains first a newline (if the input has included a newline) and all the strings finishes by the '\0' (NULL) character

Arrays

A two dimensional matrix looks like:

   mtrx_var[2][4];

Notice that this form is illegal:

   mtrx_var[2,4];

This is also valid:

   int mtrx_var[2][4] = 
       {
          {1, 2, 3, 4},
          {10, 20, 30, 40}
       };

Variables

signed: means with sign, so, values negative and positive, for example if the char variable has a limit of 255 values, using the sign mode we can use from -128 (negative) to 127 (positive), and using unsigned we can use from 0 to 255

The constant variables are constants, so they can't change, by convention they are in upper-case

Note: See TracWiki for help on using the wiki.