{"id":18023644,"url":"https://github.com/jeffotoni/c-char","last_synced_at":"2025-04-04T18:21:43.717Z","repository":{"id":134046528,"uuid":"98239513","full_name":"jeffotoni/c-char","owner":"jeffotoni","description":"Small examples to understand how char type works in C","archived":false,"fork":false,"pushed_at":"2017-10-30T18:57:39.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T03:29:19.558Z","etag":null,"topics":["c","c-example-code","c-language","c-programming"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffotoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-24T22:15:45.000Z","updated_at":"2023-02-03T04:16:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d7092f8-3102-4448-9b3d-11b4a300cd94","html_url":"https://github.com/jeffotoni/c-char","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fc-char","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fc-char/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fc-char/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fc-char/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/c-char/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226312,"owners_count":20904487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-example-code","c-language","c-programming"],"created_at":"2024-10-30T07:10:09.433Z","updated_at":"2025-04-04T18:21:43.700Z","avatar_url":"https://github.com/jeffotoni.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# c-char\nSmall examples to understand how char type works in C\n\n```c\n/**\n*\n* @author\t\t@jeffotoni\n* @copyright\tCopyright (c) 2017\n* \n* Different ways to declare a string using char\n*\n*/\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstring.h\u003e\n\n\n/**\n*\n* Defining typedef of type char as vector\n*\n*/\ntypedef char string[];\n\n/**\n*\n* Defining typedef of char type as vector pointer\n*\n*/\ntypedef char *string2[];\n\n/**\n*\n* Defining typedef of type char as pointer\n*\n*/\ntypedef char *string3;\n\n\n/**\n*\n* Main function\n*\n*/\nint main(){\n\t\n\t/**\n\t*\n\t* Defining a pointer with char and assigning a value\n\t*\n\t*/\n\tchar *stringx = \"Avocado is delicious.\";\n\n\t/**\n\t*\n\t* Defining a char pointer statically\n\t*\n\t*/\n\tchar *fstring[0];\n\n\t/**\n\t*\n\t* Knowing the size of the char\n\t*\n\t*/\n\tint size = strlen(stringx) + 1;\n\n\t/**\n\t*\n\t* Our first example using pointer char\n\t*\n\t*/\n\tfstring[0] = (char*) malloc(size * sizeof(char));\n\n\t/**\n\t*\n\t* Copying content stringx to fstring\n\t*\n\t*/\n\tstrcpy(fstring[0], stringx);\n\t\n\t/**\n\t*\n\t* Showing the result\n\t*\n\t*/\n\tprintf(\"\\nfstring: %s\\n\", fstring[0]);\n\n\t\n\t/**\n\t*\n\t* Second example\n\t*\n\t*/\n\tchar stringy[strlen(stringx)];\n\n\n\t/**\n\t*\n\t* Copying content stringx to fstring\n\t*\n\t*/\n\tstrcpy(stringy, stringx);\n\n\t/**\n\t*\n\t* Showing the result stringy\n\t*\n\t*/\n\tprintf(\"\\nstringy: %s\\n\", stringy);\n\n\n\t/**\n\t*\n\t* Declaring a vector\n\t*\n\t*/\n\tchar *fstringx[] = {};\n\n\t/**\n\t*\n\t* Allocating memory for the vect\n\t*\n\t*/\n\tfstringx[0] = (char*) malloc(size * sizeof(char));\n\n\t/**\n\t*\n\t* Copying content stringx to fstring\n\t*\n\t*/\n\tstrcpy(fstringx[0], stringx);\n\n\t/**\n\t*\n\t* Showing the result stringy\n\t*\n\t*/\n\tprintf(\"\\nfstringx: %s\\n\", fstringx[0]);\n\n\t\n\t/**\n\t*\n\t* Declaring a vector pointer to pointer\n\t*\n\t*/\n\t// char **fstringy[] = {};\n\n\n\t/**\n\t*\n\t* Declaring a string\n\t*\n\t*/\n\tstring String = \"jefferson name complete\";\n\n\t/**\n\t*\n\t* Declaring a string {}\n\t*\n\t*/\n\tstring2 String2 = {\"jefferson something\", \"something there\"};\n\n\n\t/**\n\t*\n\t* Declaring a array\n\t*\n\t*/\n\tchar **array = (char**) malloc((10+1)*sizeof(char*));\n\n\t/**\n\t*\n\t* Assigning values in our array\n\t*\n\t*/\n\tarray[0] = \"fluffy\";\n\tarray[1] = \"small\";\n\tarray[2] = \"bunny\";\n\tarray[3] = 0;\n\n\t/**\n\t*\n\t* Declaring a y int\n\t*\n\t*/\n\tint y[2][3] = { {10,20,30}, {100,200,300} };\n\n\t/**\n\t*\n\t* Declaring a x char\n\t*\n\t*/\n\tchar x[2][3] = {\"jef\",\"ola\"};\n\n\t\n\t/**\n\t*\n\t* Declaring pointer c\n\t*\n\t*/\n\tchar* c[] = {\"jef\",\"ola\",\"sel\"};\n\n\n\t/**\n\t*\n\t* Declaring vect work\n\t*\n\t*/\n\tchar work[] = {\"I work here\"};\n\n\t/**\n\t*\n\t* Declaring vect work2\n\t*\n\t*/\n\tchar work2[] = {'A','B','C'};\n\n\t\n\t/**\n\t*\n\t* Declaring pointer vect strings\n\t*\n\t*/\t\n\tchar* strings[3];\n\n\tstrings[0] = \"foo\";\n\tstrings[1] = \"bar\";\n\tstrings[2] = \"baz\";\n\tstrings[3] = \"jef\";\n\tstrings[4] = \"je2\";\n\t\n\n\t/**\n\t*\n\t* Declaring a1\n\t*\n\t*/\t\n\tchar a1[][14] = { \"Hello\", \"folks\" };\n\t\n\t/**\n\t*\n\t* Declaring a2\n\t*\n\t*/\n\tchar* a2[] = { \"Hello\", \"guys\" };\n\n\t/**\n\t*\n\t* Declaring a3\n\t*\n\t*/\n\tchar (*a3[])[] = { \u0026\"Guys\", \u0026\"People\" };\n\t\n\n\tprintf(\"\\n[%s]  [%s]\\n\",a1[0], a1[1]);\n\tprintf(\"\\n[%s] [%s]\\n\",a2[0], a2[1]);\n\tprintf(\"\\n[%s] [%s]\\n\", *a3[0], *a3[1]);\n\t\t\n}\n```\n\n# Compiling\n\n```c\n$ gcc char.c -o char\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fc-char","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fc-char","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fc-char/lists"}