https://github.com/Harry-Ross/vscode-c-snippets
A simple extension for Visual Studio Code snippets for the C programming language.
https://github.com/Harry-Ross/vscode-c-snippets
c snippets visual-studio
Last synced: 11 months ago
JSON representation
A simple extension for Visual Studio Code snippets for the C programming language.
- Host: GitHub
- URL: https://github.com/Harry-Ross/vscode-c-snippets
- Owner: Harry-Ross
- License: mit
- Created: 2019-06-25T10:55:49.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-11-05T04:22:08.000Z (over 2 years ago)
- Last Synced: 2024-08-07T18:33:27.249Z (almost 2 years ago)
- Topics: c, snippets, visual-studio
- Language: JavaScript
- Homepage: https://marketplace.visualstudio.com/items?itemName=Harry-Ross-Software.c-snippets
- Size: 974 KB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# C Snippets
This extension provides a simple set of VSCode snippets for the C programming language. Can be found [here on the Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=Harry-Ross-Software.c-snippets).






# List of snippets:
| Snippet Description | Snippet Input | Snippet Code |
| ----------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------- |
| Starter Template | `sst` | #include
int main (int argc, char *argv[]) {
return 0;
} |
| Starter template with stlib.h | `libsst` | #include
#include
int main (int argc, char *argv[]) {
return 0;
} |
| Conditionals and loops | | |
| If statement| `if` | if (expression) {
/* code here */
} |
| Else if statement | `elif` | elseif (expression) {
/* code here */
} |
| Else statement | `else` | else {
/* code here */
} |
| For loop | `for` | for (int i = 0; i < count; i++) {
/* code here */
} |
| While loop | `while` | while (expression) {
/* code here */
} |
| Do...while loop | `dowhile` | do {
/* code here */
} while (expression) |
| Header file include guard | `ig` | #ifndef {transformed_file_name}
#define {transformed_file_name}
// Code for header body
#endif {transformed_file_name} |
| Linked lists | | |
| Linked list template | `clist` | typedef struct _node * Link;
typedef struct _node node;
struct _node {
int value;
Link next;
}; |
| Functions | | |
| Create int function | `intfunc` | int func_name () {
int x;
return x;
} |
| Create float function | `flfunc` | float func_name () {
float x;
return x;
} |
| Create string function | `strfunc` | char[] func_name () {
char[] x = {};
return x;
} |
| Create long function | `longfunc` | long func_name () {
long x;
return x;
} |
| Create definition for virtual table| `vtdef` | typedef struct {ClassName}{
struct {ClassNameVT}* vt;
};
typedef struct {ClassNameVT}
{
// Virtual Table Function definitions
} ${virtualTable Name};
int {ClassNameInit}(struct {ClassName} *self);
int {ClassNameDestroy}(struct {ClassName} **self); |
| Create function for virtual table| `vtfunc` | {ReturnType} (*{FunctionName})(struct {ClassName} *self) |
| Print statements | | |
| Print variable of type float (2 decimal places) | `pflo` | printf(\"var_name :>> %.2f\\n\", var_name); |
| Print variable of type int | `pint` | printf(\"var_name :>> %d\\n\", var_name); |
| Print variable of type char | `pcha` | printf(\"var_name :>> %c\\n\", var_name); |
| Print variable of type pointer | `ppoint` | printf(\"var_name :>> %p\\n\", (void *) var_name); |
| Print variable of type size_t | `psiz` | printf(\"var_name :>> %zu\\n\", var_name); |
| Memory Allocation | | |
| Allocate memory using calloc | `cal` | {type} *ptr = ({type}*)calloc(, sizeof({type}));
if (ptr == NULL) {
printf("Memory allocation failed!\n");
exit(0);
}
free(ptr); |
If you would like to support development of the extension donate Bitcoin here: **1BnrjF49owBx7UjMaJt5crZw5DegUYG3mb**
#### Authors: [Harry Ross](https://github.com/Harry-Ross) and [Luca Merzetti](https://github.com/lucamerzi)