Created
September 5, 2020 12:26
-
-
Save skuralll/1bbe329d975dea0933173cbc8fe16465 to your computer and use it in GitHub Desktop.
string型に似たようなもの(可変長文字配列)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef struct | |
{ | |
int len; | |
char str[]; | |
} string; | |
string* getString(char chars[], int length){ | |
string* ret = malloc(sizeof(string) + sizeof(char)*length); | |
ret->len = length; | |
strcpy(ret->str, chars); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.jpcert.or.jp/sc-rules/c-dcl38-c.html
この構造体を用いた配列は作れないためこのコードに実用性はない