User:Paradox-01/C: Difference between revisions

m
+cat
(Created page with "==IDE== * CodeBlocks * Visual Studio ** Choose C++ template (empty project). Add new file but rename extension from cpp to c. ==.h== .h (header) files define functions and ar...")
 
m (+cat)
 
(5 intermediate revisions by one other user not shown)
Line 3: Line 3:
* Visual Studio
* Visual Studio
** Choose C++ template (empty project). Add new file but rename extension from cpp to c.
** Choose C++ template (empty project). Add new file but rename extension from cpp to c.
==Language==
C exists in different versions, the so called [[wp:ANSI_C#History_and_outlook|standards]]: ANSI/C90, [https://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf C99], C11, ...


==.h==
==.h==
.h (header) files define functions and are needed so they can be called independently from their appearance in the c file.
.h (header) files define functions and are needed so they can be called independently from their appearance (order) in the c file.


==.c files==
==.c files==
Line 77: Line 80:
  //#include <stdbool.h>
  //#include <stdbool.h>
  //bool a = true;
  //bool a = true;
// C99 standard
  [https://stackoverflow.com/questions/8724349/difference-between-bool-and-bool-types-in-c _Bool b = 1;]
  [https://stackoverflow.com/questions/8724349/difference-between-bool-and-bool-types-in-c _Bool b = 1;]


Line 84: Line 89:


----
----
Arrays, pointers, conversions, globals, ...
 
Arrays, pointers, conversions, globals, [https://stackoverflow.com/questions/10586003/try-catch-statements-in-c try catch simulation], [https://stackoverflow.com/questions/154136/why-use-apparently-meaningless-do-while-and-if-else-statements-in-macros?rq=1 macros] ...
 
----
 
==Files==
 
==Directories==
_getcwd can be used to get program path when main function arg is not an option.
 
#include <direct.h> // _getcwd
#include <stdlib.h> // free, perror
#include <stdio.h>  // printf
#include <string.h> // strlen
int main( void )
{
    char* buffer;
    // Get the current working directory:
    if ( (buffer = _getcwd( NULL, 0 )) == NULL )
      perror( "_getcwd error" );
    else
    {
      printf( "%s \nLength: %zu\n", buffer, strlen(buffer) );
      free(buffer);
    }
}
 
[[Category:Userspace]]