n is not substituted using strtokdeveloped a strtok alternativeHow does strtok() split the string into tokens in C?Program run in child process doesn't loopadd null end of stringCannot concatenate strtok's output variable. strcat and strtokUnhandled exception for strlen in CWhy doesn't C function with char** param set value of a pointer to char[] argHow to correctly cast void pointer to blob to a struct-pointer?My C code doesnt workDangerous script Will it work?
If a (distance) metric on a connected Riemannian manifold locally agrees with the Riemannian metric, is it equal to the induced metric?
Does French have the English "short i" vowel?
Freedom of Speech and Assembly in China
Is keeping the forking link on a true fork necessary (Github/GPL)?
Can a character with the War Caster feat call a bolt with Call Lightning instead of making an opportunity attack?
Why haven't we yet tried accelerating a space station with people inside to a near light speed?
Why did the person in charge of a principality not just declare themself king?
How to politely tell someone they did not hit "reply to all" in an email?
Writing style before Elements of Style
Where is Jon going?
How to make the Bass in SATB move more smoothly?
Why did it take so long for Germany to allow electric scooters / e-rollers on the roads?
Mercedes C180 (W204) dash symbol
Need to read my home electrical Meter
USPS Back Room - Trespassing?
Is it legal to meet with potential future employers in the UK, whilst visiting from the USA
Can my floppy disk still work without a shutter spring?
Can we assume that a hash function with high collision resistance also means highly uniform distribution?
Testing using real data of the customer
Navigating a quick return to previous employer
How to cut a climbing rope?
What is the view of Buddhism in correcting others' view in spite of their willingness to accept it?
What weight should be given to writers groups critiques?
Did this character show any indication of wanting to rule before S8E6?
n is not substituted using strtok
developed a strtok alternativeHow does strtok() split the string into tokens in C?Program run in child process doesn't loopadd null end of stringCannot concatenate strtok's output variable. strcat and strtokUnhandled exception for strlen in CWhy doesn't C function with char** param set value of a pointer to char[] argHow to correctly cast void pointer to blob to a struct-pointer?My C code doesnt workDangerous script Will it work?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to use the C's strtok function in order to process a char* and print it in a display, and looks like that for some reason I don't know the character 'n' is not substituted by '' as I believe strtok does. The code is as follows:
-Declaration of char* and pass to the function where it will be processed:
char *string_to_write = "Some textnSome other textnNewtext";
malloc(sizeof string_to_write);
screen_write(string_to_write,ALIGN_LEFT_TOP,I2C0);
-Processing of char* in function:
void screen_write(char *string_to_write,short alignment,short I2C)
char *stw;
stw = string_to_write;
char* text_to_send;
text_to_send=strtok(stw,"n");
while(text_to_send != NULL)
write_text(text_to_send,I2C);
text_to_send=strtok(NULL, "n");
When applying the code, the result can be seen in imgur (Sorry, I am having problems with format adding the image here in the post), where it can be seen that the n is not substituted as it is the strange character appearing in the image, and the debugger still showed the character as well. Any hints of where can the problem be?
Thanks for your help,
Javier
c pointers strtok
add a comment |
I am trying to use the C's strtok function in order to process a char* and print it in a display, and looks like that for some reason I don't know the character 'n' is not substituted by '' as I believe strtok does. The code is as follows:
-Declaration of char* and pass to the function where it will be processed:
char *string_to_write = "Some textnSome other textnNewtext";
malloc(sizeof string_to_write);
screen_write(string_to_write,ALIGN_LEFT_TOP,I2C0);
-Processing of char* in function:
void screen_write(char *string_to_write,short alignment,short I2C)
char *stw;
stw = string_to_write;
char* text_to_send;
text_to_send=strtok(stw,"n");
while(text_to_send != NULL)
write_text(text_to_send,I2C);
text_to_send=strtok(NULL, "n");
When applying the code, the result can be seen in imgur (Sorry, I am having problems with format adding the image here in the post), where it can be seen that the n is not substituted as it is the strange character appearing in the image, and the debugger still showed the character as well. Any hints of where can the problem be?
Thanks for your help,
Javier
c pointers strtok
sizeofdoes not work for a pointer. Usestrlen() + 1.
– Antti Haapala
Mar 24 at 0:41
You cannotstrtoka string literal. You do not seem to save the return value ofmallocanywhere.
– Antti Haapala
Mar 24 at 0:42
1
@AnttiHaapala In fairness,sizeofdoes work on an array…OP just hasn't made an array here (like I'm guessing they wanted to).
– Draconis
Mar 24 at 0:58
What is the idea of callingmalloc(sizeof string_to_write);without using its result?
– alk
Mar 24 at 13:16
add a comment |
I am trying to use the C's strtok function in order to process a char* and print it in a display, and looks like that for some reason I don't know the character 'n' is not substituted by '' as I believe strtok does. The code is as follows:
-Declaration of char* and pass to the function where it will be processed:
char *string_to_write = "Some textnSome other textnNewtext";
malloc(sizeof string_to_write);
screen_write(string_to_write,ALIGN_LEFT_TOP,I2C0);
-Processing of char* in function:
void screen_write(char *string_to_write,short alignment,short I2C)
char *stw;
stw = string_to_write;
char* text_to_send;
text_to_send=strtok(stw,"n");
while(text_to_send != NULL)
write_text(text_to_send,I2C);
text_to_send=strtok(NULL, "n");
When applying the code, the result can be seen in imgur (Sorry, I am having problems with format adding the image here in the post), where it can be seen that the n is not substituted as it is the strange character appearing in the image, and the debugger still showed the character as well. Any hints of where can the problem be?
Thanks for your help,
Javier
c pointers strtok
I am trying to use the C's strtok function in order to process a char* and print it in a display, and looks like that for some reason I don't know the character 'n' is not substituted by '' as I believe strtok does. The code is as follows:
-Declaration of char* and pass to the function where it will be processed:
char *string_to_write = "Some textnSome other textnNewtext";
malloc(sizeof string_to_write);
screen_write(string_to_write,ALIGN_LEFT_TOP,I2C0);
-Processing of char* in function:
void screen_write(char *string_to_write,short alignment,short I2C)
char *stw;
stw = string_to_write;
char* text_to_send;
text_to_send=strtok(stw,"n");
while(text_to_send != NULL)
write_text(text_to_send,I2C);
text_to_send=strtok(NULL, "n");
When applying the code, the result can be seen in imgur (Sorry, I am having problems with format adding the image here in the post), where it can be seen that the n is not substituted as it is the strange character appearing in the image, and the debugger still showed the character as well. Any hints of where can the problem be?
Thanks for your help,
Javier
c pointers strtok
c pointers strtok
asked Mar 24 at 0:24
JavierJavier
1388
1388
sizeofdoes not work for a pointer. Usestrlen() + 1.
– Antti Haapala
Mar 24 at 0:41
You cannotstrtoka string literal. You do not seem to save the return value ofmallocanywhere.
– Antti Haapala
Mar 24 at 0:42
1
@AnttiHaapala In fairness,sizeofdoes work on an array…OP just hasn't made an array here (like I'm guessing they wanted to).
– Draconis
Mar 24 at 0:58
What is the idea of callingmalloc(sizeof string_to_write);without using its result?
– alk
Mar 24 at 13:16
add a comment |
sizeofdoes not work for a pointer. Usestrlen() + 1.
– Antti Haapala
Mar 24 at 0:41
You cannotstrtoka string literal. You do not seem to save the return value ofmallocanywhere.
– Antti Haapala
Mar 24 at 0:42
1
@AnttiHaapala In fairness,sizeofdoes work on an array…OP just hasn't made an array here (like I'm guessing they wanted to).
– Draconis
Mar 24 at 0:58
What is the idea of callingmalloc(sizeof string_to_write);without using its result?
– alk
Mar 24 at 13:16
sizeof does not work for a pointer. Use strlen() + 1.– Antti Haapala
Mar 24 at 0:41
sizeof does not work for a pointer. Use strlen() + 1.– Antti Haapala
Mar 24 at 0:41
You cannot
strtok a string literal. You do not seem to save the return value of malloc anywhere.– Antti Haapala
Mar 24 at 0:42
You cannot
strtok a string literal. You do not seem to save the return value of malloc anywhere.– Antti Haapala
Mar 24 at 0:42
1
1
@AnttiHaapala In fairness,
sizeof does work on an array…OP just hasn't made an array here (like I'm guessing they wanted to).– Draconis
Mar 24 at 0:58
@AnttiHaapala In fairness,
sizeof does work on an array…OP just hasn't made an array here (like I'm guessing they wanted to).– Draconis
Mar 24 at 0:58
What is the idea of calling
malloc(sizeof string_to_write); without using its result?– alk
Mar 24 at 13:16
What is the idea of calling
malloc(sizeof string_to_write); without using its result?– alk
Mar 24 at 13:16
add a comment |
2 Answers
2
active
oldest
votes
strtok expects to be able to mutate the string you pass it: instead of allocating new memory for each token, it puts characters into the string at token boundaries, then returns a series of pointers into that string.
But in this case, your string is immutable: it's a constant stored in your program, and can't be changed. So strtok is doing its best: it's returning indices into the string for each token's starting point, but it can't insert the s to mark the ends. Your device can't handle ns in the way you'd expect, so it displays them with that error character instead. (Which is presumably why you're using this code in the first place.)
The key is to pass in only mutable strings. To define a mutable string with a literal value, you need char my_string[] = "..."; rather than char* my_string = "...". In the latter case, it just gives you a pointer to some constant memory; in the former case, it actually makes an array for you to use. Alternately, you can use strlen to find out how long the string is, malloc some memory for it, then strcpy it over.
P.S. I'm concerned by your malloc: you're not saving the memory it gives you anywhere, and you're not doing anything with it. Be sure you know what you're doing before working with dynamic memory allocation! C is not friendly about that, and it's easy to start leaking without realizing it.
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
add a comment |
1.
malloc(sizeof string_to_write); - it allocates the sizeof(char *) bytes not as many bytes as your string needs. You also do not assign the allocated block to anything
2.
char *string_to_write = "Some textnSome other textnNewtext";
char *ptr;
ptr = malloc(strlen(string_to_write) + 1);
strcpy(ptr, string_to_write);
screen_write(ptr,ALIGN_LEFT_TOP,I2C0);
This is absolutely correct, but you might want to explain why exactly you need a mutable string forstrtok. (And maybe mentionfree, since I'm guessing OP is new to manual memory management.)
– Draconis
Mar 24 at 1:01
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%2f55319633%2fn-is-not-substituted-using-strtok%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
strtok expects to be able to mutate the string you pass it: instead of allocating new memory for each token, it puts characters into the string at token boundaries, then returns a series of pointers into that string.
But in this case, your string is immutable: it's a constant stored in your program, and can't be changed. So strtok is doing its best: it's returning indices into the string for each token's starting point, but it can't insert the s to mark the ends. Your device can't handle ns in the way you'd expect, so it displays them with that error character instead. (Which is presumably why you're using this code in the first place.)
The key is to pass in only mutable strings. To define a mutable string with a literal value, you need char my_string[] = "..."; rather than char* my_string = "...". In the latter case, it just gives you a pointer to some constant memory; in the former case, it actually makes an array for you to use. Alternately, you can use strlen to find out how long the string is, malloc some memory for it, then strcpy it over.
P.S. I'm concerned by your malloc: you're not saving the memory it gives you anywhere, and you're not doing anything with it. Be sure you know what you're doing before working with dynamic memory allocation! C is not friendly about that, and it's easy to start leaking without realizing it.
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
add a comment |
strtok expects to be able to mutate the string you pass it: instead of allocating new memory for each token, it puts characters into the string at token boundaries, then returns a series of pointers into that string.
But in this case, your string is immutable: it's a constant stored in your program, and can't be changed. So strtok is doing its best: it's returning indices into the string for each token's starting point, but it can't insert the s to mark the ends. Your device can't handle ns in the way you'd expect, so it displays them with that error character instead. (Which is presumably why you're using this code in the first place.)
The key is to pass in only mutable strings. To define a mutable string with a literal value, you need char my_string[] = "..."; rather than char* my_string = "...". In the latter case, it just gives you a pointer to some constant memory; in the former case, it actually makes an array for you to use. Alternately, you can use strlen to find out how long the string is, malloc some memory for it, then strcpy it over.
P.S. I'm concerned by your malloc: you're not saving the memory it gives you anywhere, and you're not doing anything with it. Be sure you know what you're doing before working with dynamic memory allocation! C is not friendly about that, and it's easy to start leaking without realizing it.
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
add a comment |
strtok expects to be able to mutate the string you pass it: instead of allocating new memory for each token, it puts characters into the string at token boundaries, then returns a series of pointers into that string.
But in this case, your string is immutable: it's a constant stored in your program, and can't be changed. So strtok is doing its best: it's returning indices into the string for each token's starting point, but it can't insert the s to mark the ends. Your device can't handle ns in the way you'd expect, so it displays them with that error character instead. (Which is presumably why you're using this code in the first place.)
The key is to pass in only mutable strings. To define a mutable string with a literal value, you need char my_string[] = "..."; rather than char* my_string = "...". In the latter case, it just gives you a pointer to some constant memory; in the former case, it actually makes an array for you to use. Alternately, you can use strlen to find out how long the string is, malloc some memory for it, then strcpy it over.
P.S. I'm concerned by your malloc: you're not saving the memory it gives you anywhere, and you're not doing anything with it. Be sure you know what you're doing before working with dynamic memory allocation! C is not friendly about that, and it's easy to start leaking without realizing it.
strtok expects to be able to mutate the string you pass it: instead of allocating new memory for each token, it puts characters into the string at token boundaries, then returns a series of pointers into that string.
But in this case, your string is immutable: it's a constant stored in your program, and can't be changed. So strtok is doing its best: it's returning indices into the string for each token's starting point, but it can't insert the s to mark the ends. Your device can't handle ns in the way you'd expect, so it displays them with that error character instead. (Which is presumably why you're using this code in the first place.)
The key is to pass in only mutable strings. To define a mutable string with a literal value, you need char my_string[] = "..."; rather than char* my_string = "...". In the latter case, it just gives you a pointer to some constant memory; in the former case, it actually makes an array for you to use. Alternately, you can use strlen to find out how long the string is, malloc some memory for it, then strcpy it over.
P.S. I'm concerned by your malloc: you're not saving the memory it gives you anywhere, and you're not doing anything with it. Be sure you know what you're doing before working with dynamic memory allocation! C is not friendly about that, and it's easy to start leaking without realizing it.
answered Mar 24 at 0:55
DraconisDraconis
1,9521019
1,9521019
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
add a comment |
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
Thanks a lot Draconis for your answer, it worked! Indeed for the display font chip n is somehow understood as the character shown, and also I want to play with it in terms of positioning in the display, that's why I thought of using strtok. One more question, is there any useful link you know for pointers and examples? It is something I really need to work with.
– Javier
Mar 24 at 21:04
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
@Javier I'm afraid I don't know of one; I learned pointers in some CS class years ago. But "how can I learn more about pointers in C" seems like a perfectly valid question to ask on this site!
– Draconis
Mar 25 at 0:50
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
Ok, thanks anyway. I also learned about pointers at university, but it already passed some time since then haha
– Javier
Mar 25 at 20:52
add a comment |
1.
malloc(sizeof string_to_write); - it allocates the sizeof(char *) bytes not as many bytes as your string needs. You also do not assign the allocated block to anything
2.
char *string_to_write = "Some textnSome other textnNewtext";
char *ptr;
ptr = malloc(strlen(string_to_write) + 1);
strcpy(ptr, string_to_write);
screen_write(ptr,ALIGN_LEFT_TOP,I2C0);
This is absolutely correct, but you might want to explain why exactly you need a mutable string forstrtok. (And maybe mentionfree, since I'm guessing OP is new to manual memory management.)
– Draconis
Mar 24 at 1:01
add a comment |
1.
malloc(sizeof string_to_write); - it allocates the sizeof(char *) bytes not as many bytes as your string needs. You also do not assign the allocated block to anything
2.
char *string_to_write = "Some textnSome other textnNewtext";
char *ptr;
ptr = malloc(strlen(string_to_write) + 1);
strcpy(ptr, string_to_write);
screen_write(ptr,ALIGN_LEFT_TOP,I2C0);
This is absolutely correct, but you might want to explain why exactly you need a mutable string forstrtok. (And maybe mentionfree, since I'm guessing OP is new to manual memory management.)
– Draconis
Mar 24 at 1:01
add a comment |
1.
malloc(sizeof string_to_write); - it allocates the sizeof(char *) bytes not as many bytes as your string needs. You also do not assign the allocated block to anything
2.
char *string_to_write = "Some textnSome other textnNewtext";
char *ptr;
ptr = malloc(strlen(string_to_write) + 1);
strcpy(ptr, string_to_write);
screen_write(ptr,ALIGN_LEFT_TOP,I2C0);
1.
malloc(sizeof string_to_write); - it allocates the sizeof(char *) bytes not as many bytes as your string needs. You also do not assign the allocated block to anything
2.
char *string_to_write = "Some textnSome other textnNewtext";
char *ptr;
ptr = malloc(strlen(string_to_write) + 1);
strcpy(ptr, string_to_write);
screen_write(ptr,ALIGN_LEFT_TOP,I2C0);
answered Mar 24 at 0:57
P__J__P__J__
13.1k2827
13.1k2827
This is absolutely correct, but you might want to explain why exactly you need a mutable string forstrtok. (And maybe mentionfree, since I'm guessing OP is new to manual memory management.)
– Draconis
Mar 24 at 1:01
add a comment |
This is absolutely correct, but you might want to explain why exactly you need a mutable string forstrtok. (And maybe mentionfree, since I'm guessing OP is new to manual memory management.)
– Draconis
Mar 24 at 1:01
This is absolutely correct, but you might want to explain why exactly you need a mutable string for
strtok. (And maybe mention free, since I'm guessing OP is new to manual memory management.)– Draconis
Mar 24 at 1:01
This is absolutely correct, but you might want to explain why exactly you need a mutable string for
strtok. (And maybe mention free, since I'm guessing OP is new to manual memory management.)– Draconis
Mar 24 at 1:01
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%2f55319633%2fn-is-not-substituted-using-strtok%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
sizeofdoes not work for a pointer. Usestrlen() + 1.– Antti Haapala
Mar 24 at 0:41
You cannot
strtoka string literal. You do not seem to save the return value ofmallocanywhere.– Antti Haapala
Mar 24 at 0:42
1
@AnttiHaapala In fairness,
sizeofdoes work on an array…OP just hasn't made an array here (like I'm guessing they wanted to).– Draconis
Mar 24 at 0:58
What is the idea of calling
malloc(sizeof string_to_write);without using its result?– alk
Mar 24 at 13:16