meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
digital:programmieren:c [2019/01/11 12:19]
natrius [Main Function]
digital:programmieren:c [2022/02/22 16:44]
natrius removed
Line 1: Line 1:
 # C # C
 +
 Zusammenfassung für nützliche Sachen beim Programmieren mit C. Zusammenfassung für nützliche Sachen beim Programmieren mit C.
  
 ## Ressourcen ## Ressourcen
 +
 +  * https://github.com/kozross/awesome-c#learning-reference-and-tutorials
   * https://de.wikibooks.org/wiki/C-Programmierung   * https://de.wikibooks.org/wiki/C-Programmierung
   * http://www.code-in-c.com/galton-board-in-c/   * http://www.code-in-c.com/galton-board-in-c/
   * http://www.c-howto.de/tutorial/einfuehrung/   * http://www.c-howto.de/tutorial/einfuehrung/
 +  * http://www.vazgames.com/retro/CPROG.htm
 +  * http://ergodic.ugr.es/cphys_pedro/c/c/ccourse.html
 +  * ALGORITHMS http://www-igm.univ-mlv.fr/~lecroq/string/index.html
 +  * Propositional Logic: Introduction https://www.youtube.com/watch?v=qV4htTfow-E&list=PL619166130C21EADA
 +  * https://www.gnu.org/software/libc/manual/html_node/Getopt.html
 +  * Allgemein, MultiOS-Gamedev: https://gist.github.com/flibitijibibo/b67910842ab95bb3decdf89d1502de88
 +  * https://www.reddit.com/r/C_Programming/comments/cep9zl/c_skill_tree_visual_guide_for_c_resources/
 +  * Structure my program https://www.reddit.com/r/C_Programming/comments/cadkxr/c_programming_beginner_needs_help/?sort=top
 +  * https://www.reddit.com/r/C_Programming/comments/b3f9n5/i_created_a_simple_tictactoe_game_and_am_looking/?sort=top
 +  * http://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html
 +  * http://rosettacode.org/wiki/Category:Programming_Tasks
  
-## Input seperated with space or /+### Starting a project, planning
  
-  * https://stackoverflow.com/questions/15330047/understanding-scanf-dealing-with-formatted-input+  * https://www.quora.com/How-do-I-start-my-own-programming-projects-1 
 +  * https://www.codeconquest.com/programming-projects/ 
 +  * https://www.khanacademy.org/computing/computer-programming/programming/good-practices/a/planning-a-programming-project
  
-To match both the space-separated and the slash-separated inputs, you'll need a modestly complex format string:+### Games
  
-<code> +  https://www.codingame.com/home 
-if (scanf("%[^ /]%*1[ /]%d%*1[ /]%f", name, &age, &wage) == 3) +  * https://www.coderbyte.com
-    ...data was read properly... +  https://www.reddit.com/r/C_Programming/comments/c3ap6f/i_just_started_a_new_project_on_github_with_code/?sort=top 
-else +  https://projecteuler.net/ 
-    ...something went wrong... +  * https://www.reddit.com/r/dailyprogrammer/ 
-</code> +  * https://www.hackerrank.com/ 
- +  * paid? https://www.topcoder.com/
-The first conversion specification is a scan set that accepts a sequence of non-blanks, non-slashes (so it will stop at the first blank or slash). It would be best to specify an upper bound on how many characters will be accepted so as to avoid stack overflow; for example, if char name[32];, then %31[^ /] (note the off-by-one). The second conversion specification %*1[ /] accepts a single character (1) that is either a blank or slash [ /], and does not assign it to any variable (*)The third conversion specification is a standard numeric input, skipping leading blanks, allowing for negative numbers to be entered, etc. The fourth conversion specification is the same as the second, and the fifth is a standard format for a float (which means that 34000.25 with 7 significant digits is at the outer end of the range of representable values)+
- +
-Note that the 'something went wrong' part has a difficult time reporting the error coherently to the user. This is why many people, myself included, recommend against using scanf() or fscanf() and prefer to use fgets() or perhaps POSIX getline to read a line from the user and then use sscanf() to analyze it. You can report the problems much more easily. Also note that the return value from scanf() is the number of successful assignments; it does not count the conversion specifications that include *. +
- +
-##  Datentypen +
- +
-^ Type                                          ^ Keyword         | Bytes  | Range                               | +
-| character                                     | char            | 1      | -128 .. 127                       | +
-| unsigned character                            | unsigned char   | 1      | 0 .. 255                          | +
-| integer                                       | int             | 2      | -32 768 .. 32 767                 | +
-| short integer                                 | short           | 2      | -32 768 .. 32 767                 | +
-| long integer                                  | long            | 4      | -2 147 483 648 .. 2 147 483 647   | +
-| unsigned integer                              | unsigned int    | 2      | 0 .. 65 535                       | +
-| unsigned short integer                        | unsigned short  | 2      | 0 .. 65 535                       | +
-| unsigned long integer                         | unsigned long   | 4      | 0 .. 4 294 967 295                | +
-| single-precision floating-point (7 Stellen)   | float           | 4      | 1.17E-38 .. 3.4E38                | +
-| double-precision floating-point (19 Stellen)  | double          | 8      | 2.2E-308 .. 1.8E308               |+
  
 ## Cheat Sheet ## Cheat Sheet
Line 50: Line 49:
 ### Printf ### Printf
  
-<code>+<code c>
 #include <stdio.h> #include <stdio.h>
  
Line 72: Line 71:
 ### Scanf ### Scanf
  
-<code>+<code c>
 #include <stdio.h> #include <stdio.h>
  
Line 86: Line 85:
 ### Conditionals ### Conditionals
  
-<code>+<code c>
 if(flag) { if(flag) {
    // put some statements here to execute if flag is true (flag != 0)    // put some statements here to execute if flag is true (flag != 0)
Line 111: Line 110:
 ### Looping ### Looping
  
-<code>+<code c>
 while(flag) { while(flag) {
     // make sure there is some statement in here to change flag to become false.     // make sure there is some statement in here to change flag to become false.
Line 123: Line 122:
 ### Math Functions ### Math Functions
  
-<code>+<code c>
 #include <math.h> #include <math.h>
  
Line 134: Line 133:
     th = atan2(y, x);     th = atan2(y, x);
 } }
-Creating Functions+</code>
  
 +### Creating Functions
 +
 +<code c>
 int functionname(type1 input1, ... , typeN *output1, ...);     // this is the function prototype with the ; int functionname(type1 input1, ... , typeN *output1, ...);     // this is the function prototype with the ;
 int functionname(type1 input1, ... , typeN *output1, ...) int functionname(type1 input1, ... , typeN *output1, ...)
Line 145: Line 147:
 } }
 </code> </code>
 +
 +## Input seperated with space or /
 +
 +  * https://stackoverflow.com/questions/15330047/understanding-scanf-dealing-with-formatted-input
 +
 +To match both the space-separated and the slash-separated inputs, you'll need a modestly complex format string:
 +
 +<code>
 +if (scanf("%[^ /]%*1[ /]%d%*1[ /]%f", name, &age, &wage) == 3)
 +    ...data was read properly...
 +else
 +    ...something went wrong...
 +</code>
 +
 +The first conversion specification is a scan set that accepts a sequence of non-blanks, non-slashes (so it will stop at the first blank or slash). It would be best to specify an upper bound on how many characters will be accepted so as to avoid stack overflow; for example, if char name[32];, then %31[^ /] (note the off-by-one). The second conversion specification %*1[ /] accepts a single character (1) that is either a blank or slash [ /], and does not assign it to any variable (*). The third conversion specification is a standard numeric input, skipping leading blanks, allowing for negative numbers to be entered, etc. The fourth conversion specification is the same as the second, and the fifth is a standard format for a float (which means that 34000.25 with 7 significant digits is at the outer end of the range of representable values).
 +
 +Note that the 'something went wrong' part has a difficult time reporting the error coherently to the user. This is why many people, myself included, recommend against using scanf() or fscanf() and prefer to use fgets() or perhaps POSIX getline to read a line from the user and then use sscanf() to analyze it. You can report the problems much more easily. Also note that the return value from scanf() is the number of successful assignments; it does not count the conversion specifications that include *.
 +
 +##  Datentypen
 +
 +^ Type                                          ^ Keyword         | Bytes  | Range                               |
 +| character                                     | char            | 1      | -128 .. 127                       |
 +| unsigned character                            | unsigned char   | 1      | 0 .. 255                          |
 +| integer                                       | int             | 2      | -32 768 .. 32 767                 |
 +| short integer                                 | short           | 2      | -32 768 .. 32 767                 |
 +| long integer                                  | long            | 4      | -2 147 483 648 .. 2 147 483 647   |
 +| unsigned integer                              | unsigned int    | 2      | 0 .. 65 535                       |
 +| unsigned short integer                        | unsigned short  | 2      | 0 .. 65 535                       |
 +| unsigned long integer                         | unsigned long   | 4      | 0 .. 4 294 967 295                |
 +| single-precision floating-point (7 Stellen)   | float           | 4      | 1.17E-38 .. 3.4E38                |
 +| double-precision floating-point (19 Stellen)  | double          | 8      | 2.2E-308 .. 1.8E308               |
  
 ## Zusammenfassung Tutorial ## Zusammenfassung Tutorial