How do I dynamically allocate memory to a pointer array inside a structure
here is what i have in done so far
struct test_case {
int n;
int *test;
};
struct test_case *test_case_struct = (struct test_case *)malloc(
sizeof(struct test_struct) + 100 * sizeof(int));
I need to allocate n pointers in the "test" pointer array. As far as i know i need to allocate space to the structure and then some more for the pointer array, but when i try to compile this, i get the error
invalid use of sizeof operator for to incomplete type struct test_struct
if someone could please inform me how i can take the value of n as a user input and have int *test [n] made possible.
c data-structures dynamic-memory-allocation
add a comment |
here is what i have in done so far
struct test_case {
int n;
int *test;
};
struct test_case *test_case_struct = (struct test_case *)malloc(
sizeof(struct test_struct) + 100 * sizeof(int));
I need to allocate n pointers in the "test" pointer array. As far as i know i need to allocate space to the structure and then some more for the pointer array, but when i try to compile this, i get the error
invalid use of sizeof operator for to incomplete type struct test_struct
if someone could please inform me how i can take the value of n as a user input and have int *test [n] made possible.
c data-structures dynamic-memory-allocation
try using typedef when you create your structure then use the type name in your sizeof.
– SPlatten
Nov 21 '18 at 7:37
Side note, but consider not casting the result of malloc.
– StoryTeller
Nov 21 '18 at 7:40
add a comment |
here is what i have in done so far
struct test_case {
int n;
int *test;
};
struct test_case *test_case_struct = (struct test_case *)malloc(
sizeof(struct test_struct) + 100 * sizeof(int));
I need to allocate n pointers in the "test" pointer array. As far as i know i need to allocate space to the structure and then some more for the pointer array, but when i try to compile this, i get the error
invalid use of sizeof operator for to incomplete type struct test_struct
if someone could please inform me how i can take the value of n as a user input and have int *test [n] made possible.
c data-structures dynamic-memory-allocation
here is what i have in done so far
struct test_case {
int n;
int *test;
};
struct test_case *test_case_struct = (struct test_case *)malloc(
sizeof(struct test_struct) + 100 * sizeof(int));
I need to allocate n pointers in the "test" pointer array. As far as i know i need to allocate space to the structure and then some more for the pointer array, but when i try to compile this, i get the error
invalid use of sizeof operator for to incomplete type struct test_struct
if someone could please inform me how i can take the value of n as a user input and have int *test [n] made possible.
c data-structures dynamic-memory-allocation
c data-structures dynamic-memory-allocation
edited Nov 21 '18 at 7:36


Sourav Ghosh
110k14130188
110k14130188
asked Nov 21 '18 at 7:33


Shiva KumarShiva Kumar
61
61
try using typedef when you create your structure then use the type name in your sizeof.
– SPlatten
Nov 21 '18 at 7:37
Side note, but consider not casting the result of malloc.
– StoryTeller
Nov 21 '18 at 7:40
add a comment |
try using typedef when you create your structure then use the type name in your sizeof.
– SPlatten
Nov 21 '18 at 7:37
Side note, but consider not casting the result of malloc.
– StoryTeller
Nov 21 '18 at 7:40
try using typedef when you create your structure then use the type name in your sizeof.
– SPlatten
Nov 21 '18 at 7:37
try using typedef when you create your structure then use the type name in your sizeof.
– SPlatten
Nov 21 '18 at 7:37
Side note, but consider not casting the result of malloc.
– StoryTeller
Nov 21 '18 at 7:40
Side note, but consider not casting the result of malloc.
– StoryTeller
Nov 21 '18 at 7:40
add a comment |
3 Answers
3
active
oldest
votes
Don't repeat type names. You already stumbled over your own code twice because you did that. You made the mistake of typing the wrong struct tag and confusing int*
for int
.
A more hardy allocation would look like this
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + sizeof (test_case_struct->test[0]) * 100);
This here will allocate the size of whatever test_case_struct
points at, plus 100 more of whatever test_case_struct->test[0]
should be. Now you can play with the structure definition without breaking this call to malloc. And if you do perform a breaking change (like renaming test
), you'll be notified by your compiler promptly.
add a comment |
You need to change
sizeof(struct test_struct)
to
sizeof(struct test_case)
as test_struct
is not the correct structure type.
In a better way, you can also use the already-declared variable name, like
struct test_case *test_case_struct = malloc(
sizeof (*test_case_struct) + n * sizeof(int*));
That said, you need to allocate memory worth of int *
s, not int
s, for the flexible member.
Also, below is a snippet which shows the count is taken as user input
int main(void)
{
int n = 0;
puts("Enter the count of pointers");
if (scanf("%d", &n) != 1) {
puts("Got a problem in the input");
exit (-1);
}
struct test_case *test_case_struct = malloc( sizeof(struct test_case) + n * sizeof(int*));
printf("Hello, world!n");
return 0;
}
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
@ShivaKumar So, you are saying, you don't need an array of pointers toint
s, rather an array ofint
s, the count of theint
s would be stored inn
, right?
– Sourav Ghosh
Nov 21 '18 at 9:19
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
add a comment |
Currently you are using flexible array(aka zero length array).
Which can be allocated as below.
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + 100 * sizeof (int *));
Note missing *
for int
and typo sizeof(struct test_struct)
in your code.
Alternatively you can use pointer to pointer as below.
struct test_case {
int n;
int **test;
};
struct test_case *test_case_struct = malloc(
sizeof(*test_case_struct));
test_case_struct->test = malloc(100 * sizeof(int *)); // Allocates 100 pointers
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
@SouravGhosh I justass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.
– kiran Biradar
Nov 21 '18 at 7:52
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407212%2fhow-do-i-dynamically-allocate-memory-to-a-pointer-array-inside-a-structure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Don't repeat type names. You already stumbled over your own code twice because you did that. You made the mistake of typing the wrong struct tag and confusing int*
for int
.
A more hardy allocation would look like this
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + sizeof (test_case_struct->test[0]) * 100);
This here will allocate the size of whatever test_case_struct
points at, plus 100 more of whatever test_case_struct->test[0]
should be. Now you can play with the structure definition without breaking this call to malloc. And if you do perform a breaking change (like renaming test
), you'll be notified by your compiler promptly.
add a comment |
Don't repeat type names. You already stumbled over your own code twice because you did that. You made the mistake of typing the wrong struct tag and confusing int*
for int
.
A more hardy allocation would look like this
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + sizeof (test_case_struct->test[0]) * 100);
This here will allocate the size of whatever test_case_struct
points at, plus 100 more of whatever test_case_struct->test[0]
should be. Now you can play with the structure definition without breaking this call to malloc. And if you do perform a breaking change (like renaming test
), you'll be notified by your compiler promptly.
add a comment |
Don't repeat type names. You already stumbled over your own code twice because you did that. You made the mistake of typing the wrong struct tag and confusing int*
for int
.
A more hardy allocation would look like this
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + sizeof (test_case_struct->test[0]) * 100);
This here will allocate the size of whatever test_case_struct
points at, plus 100 more of whatever test_case_struct->test[0]
should be. Now you can play with the structure definition without breaking this call to malloc. And if you do perform a breaking change (like renaming test
), you'll be notified by your compiler promptly.
Don't repeat type names. You already stumbled over your own code twice because you did that. You made the mistake of typing the wrong struct tag and confusing int*
for int
.
A more hardy allocation would look like this
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + sizeof (test_case_struct->test[0]) * 100);
This here will allocate the size of whatever test_case_struct
points at, plus 100 more of whatever test_case_struct->test[0]
should be. Now you can play with the structure definition without breaking this call to malloc. And if you do perform a breaking change (like renaming test
), you'll be notified by your compiler promptly.
answered Nov 21 '18 at 7:44
StoryTellerStoryTeller
98k12200267
98k12200267
add a comment |
add a comment |
You need to change
sizeof(struct test_struct)
to
sizeof(struct test_case)
as test_struct
is not the correct structure type.
In a better way, you can also use the already-declared variable name, like
struct test_case *test_case_struct = malloc(
sizeof (*test_case_struct) + n * sizeof(int*));
That said, you need to allocate memory worth of int *
s, not int
s, for the flexible member.
Also, below is a snippet which shows the count is taken as user input
int main(void)
{
int n = 0;
puts("Enter the count of pointers");
if (scanf("%d", &n) != 1) {
puts("Got a problem in the input");
exit (-1);
}
struct test_case *test_case_struct = malloc( sizeof(struct test_case) + n * sizeof(int*));
printf("Hello, world!n");
return 0;
}
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
@ShivaKumar So, you are saying, you don't need an array of pointers toint
s, rather an array ofint
s, the count of theint
s would be stored inn
, right?
– Sourav Ghosh
Nov 21 '18 at 9:19
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
add a comment |
You need to change
sizeof(struct test_struct)
to
sizeof(struct test_case)
as test_struct
is not the correct structure type.
In a better way, you can also use the already-declared variable name, like
struct test_case *test_case_struct = malloc(
sizeof (*test_case_struct) + n * sizeof(int*));
That said, you need to allocate memory worth of int *
s, not int
s, for the flexible member.
Also, below is a snippet which shows the count is taken as user input
int main(void)
{
int n = 0;
puts("Enter the count of pointers");
if (scanf("%d", &n) != 1) {
puts("Got a problem in the input");
exit (-1);
}
struct test_case *test_case_struct = malloc( sizeof(struct test_case) + n * sizeof(int*));
printf("Hello, world!n");
return 0;
}
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
@ShivaKumar So, you are saying, you don't need an array of pointers toint
s, rather an array ofint
s, the count of theint
s would be stored inn
, right?
– Sourav Ghosh
Nov 21 '18 at 9:19
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
add a comment |
You need to change
sizeof(struct test_struct)
to
sizeof(struct test_case)
as test_struct
is not the correct structure type.
In a better way, you can also use the already-declared variable name, like
struct test_case *test_case_struct = malloc(
sizeof (*test_case_struct) + n * sizeof(int*));
That said, you need to allocate memory worth of int *
s, not int
s, for the flexible member.
Also, below is a snippet which shows the count is taken as user input
int main(void)
{
int n = 0;
puts("Enter the count of pointers");
if (scanf("%d", &n) != 1) {
puts("Got a problem in the input");
exit (-1);
}
struct test_case *test_case_struct = malloc( sizeof(struct test_case) + n * sizeof(int*));
printf("Hello, world!n");
return 0;
}
You need to change
sizeof(struct test_struct)
to
sizeof(struct test_case)
as test_struct
is not the correct structure type.
In a better way, you can also use the already-declared variable name, like
struct test_case *test_case_struct = malloc(
sizeof (*test_case_struct) + n * sizeof(int*));
That said, you need to allocate memory worth of int *
s, not int
s, for the flexible member.
Also, below is a snippet which shows the count is taken as user input
int main(void)
{
int n = 0;
puts("Enter the count of pointers");
if (scanf("%d", &n) != 1) {
puts("Got a problem in the input");
exit (-1);
}
struct test_case *test_case_struct = malloc( sizeof(struct test_case) + n * sizeof(int*));
printf("Hello, world!n");
return 0;
}
edited Nov 21 '18 at 7:47
answered Nov 21 '18 at 7:42


Sourav GhoshSourav Ghosh
110k14130188
110k14130188
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
@ShivaKumar So, you are saying, you don't need an array of pointers toint
s, rather an array ofint
s, the count of theint
s would be stored inn
, right?
– Sourav Ghosh
Nov 21 '18 at 9:19
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
add a comment |
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
@ShivaKumar So, you are saying, you don't need an array of pointers toint
s, rather an array ofint
s, the count of theint
s would be stored inn
, right?
– Sourav Ghosh
Nov 21 '18 at 9:19
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
my intention is to have a pointer array that can point to n elements. where n is a user input. both n and pointer array being inside the structure. sorry for the typo in the snippet there
– Shiva Kumar
Nov 21 '18 at 9:07
@ShivaKumar So, you are saying, you don't need an array of pointers to
int
s, rather an array of int
s, the count of the int
s would be stored in n
, right?– Sourav Ghosh
Nov 21 '18 at 9:19
@ShivaKumar So, you are saying, you don't need an array of pointers to
int
s, rather an array of int
s, the count of the int
s would be stored in n
, right?– Sourav Ghosh
Nov 21 '18 at 9:19
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
nope. if i were to have a pointer array int *test[n], n would be a user input (this alone is not challenging for me, i gave done it before), the complexity is where i need to put the pointer array int *test[ ] inside a structure, and also its size int n inside a structure. the use case i am needing this for is i have the user inputting different square matrices of different dimensions (int n). each pointer in the test[0], test[1] ... test[n] is pointing to an int array which inturn have n elements in it. i hope i have made the picture clear enough.
– Shiva Kumar
Nov 22 '18 at 5:23
add a comment |
Currently you are using flexible array(aka zero length array).
Which can be allocated as below.
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + 100 * sizeof (int *));
Note missing *
for int
and typo sizeof(struct test_struct)
in your code.
Alternatively you can use pointer to pointer as below.
struct test_case {
int n;
int **test;
};
struct test_case *test_case_struct = malloc(
sizeof(*test_case_struct));
test_case_struct->test = malloc(100 * sizeof(int *)); // Allocates 100 pointers
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
@SouravGhosh I justass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.
– kiran Biradar
Nov 21 '18 at 7:52
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
add a comment |
Currently you are using flexible array(aka zero length array).
Which can be allocated as below.
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + 100 * sizeof (int *));
Note missing *
for int
and typo sizeof(struct test_struct)
in your code.
Alternatively you can use pointer to pointer as below.
struct test_case {
int n;
int **test;
};
struct test_case *test_case_struct = malloc(
sizeof(*test_case_struct));
test_case_struct->test = malloc(100 * sizeof(int *)); // Allocates 100 pointers
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
@SouravGhosh I justass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.
– kiran Biradar
Nov 21 '18 at 7:52
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
add a comment |
Currently you are using flexible array(aka zero length array).
Which can be allocated as below.
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + 100 * sizeof (int *));
Note missing *
for int
and typo sizeof(struct test_struct)
in your code.
Alternatively you can use pointer to pointer as below.
struct test_case {
int n;
int **test;
};
struct test_case *test_case_struct = malloc(
sizeof(*test_case_struct));
test_case_struct->test = malloc(100 * sizeof(int *)); // Allocates 100 pointers
Currently you are using flexible array(aka zero length array).
Which can be allocated as below.
struct test_case *test_case_struct =
malloc(sizeof (*test_case_struct) + 100 * sizeof (int *));
Note missing *
for int
and typo sizeof(struct test_struct)
in your code.
Alternatively you can use pointer to pointer as below.
struct test_case {
int n;
int **test;
};
struct test_case *test_case_struct = malloc(
sizeof(*test_case_struct));
test_case_struct->test = malloc(100 * sizeof(int *)); // Allocates 100 pointers
edited Nov 21 '18 at 7:56
answered Nov 21 '18 at 7:40


kiran Biradarkiran Biradar
5,2582926
5,2582926
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
@SouravGhosh I justass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.
– kiran Biradar
Nov 21 '18 at 7:52
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
add a comment |
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
@SouravGhosh I justass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.
– kiran Biradar
Nov 21 '18 at 7:52
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
And why flexible array is not suitable?
– Sourav Ghosh
Nov 21 '18 at 7:45
@SouravGhosh I just
ass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.– kiran Biradar
Nov 21 '18 at 7:52
@SouravGhosh I just
ass*u*me*d
OP might not intended to use flexible array and accidentally declared structure like that.– kiran Biradar
Nov 21 '18 at 7:52
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
@kiranBiradar The title suggests that an array of pointers in a struct is desired.
– Gerhardh
Nov 21 '18 at 8:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407212%2fhow-do-i-dynamically-allocate-memory-to-a-pointer-array-inside-a-structure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try using typedef when you create your structure then use the type name in your sizeof.
– SPlatten
Nov 21 '18 at 7:37
Side note, but consider not casting the result of malloc.
– StoryTeller
Nov 21 '18 at 7:40