| 1 | |
| 2 | == Comments == |
| 3 | |
| 4 | 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 |
| 5 | |
| 6 | 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 |
| 7 | |
| 8 | The special things that you need to have in mind when you code is: clarity of code, simplicity, and summary |
| 9 | |
| 10 | |
| 11 | == Basic Things == |
| 12 | |
| 13 | To declare a string in a variable, you need to use strcpy, so |
| 14 | {{{ |
| 15 | name = "Me"; /* Illegal */ |
| 16 | strcpy (name, "Me"); /* Legal */ |
| 17 | }}} |
| 18 | |
| 19 | 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 ". |
| 20 | |
| 21 | |
| 22 | 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: |
| 23 | {{{ |
| 24 | #!C |
| 25 | fgets(first, sizeof(first), stdin); |
| 26 | first[strlen(first)-1] = '\0'; |
| 27 | }}} |
| 28 | 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 |
| 29 | |
| 30 | == Arrays == |
| 31 | |
| 32 | A two dimensional matrix looks like: |
| 33 | {{{ |
| 34 | #!C |
| 35 | mtrx_var[2][4]; |
| 36 | }}} |
| 37 | |
| 38 | Notice that this form is illegal: |
| 39 | {{{ |
| 40 | #!C |
| 41 | mtrx_var[2,4]; |
| 42 | }}} |
| 43 | |
| 44 | This is also valid: |
| 45 | {{{ |
| 46 | #!C |
| 47 | int mtrx_var[2][4] = |
| 48 | { |
| 49 | {1, 2, 3, 4}, |
| 50 | {10, 20, 30, 40} |
| 51 | }; |
| 52 | }}} |
| 53 | |
| 54 | |
| 55 | == Variables == |
| 56 | |
| 57 | 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''' |
| 58 | |
| 59 | The '''constant''' variables are constants, so they can't change, by convention they are in upper-case |
| 60 | |