Losing last character in string when reading a value from a line in a CSV
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm trying to parse through a line of a CSV file and pull out the desired value that I want. However, my function is cutting off the last character in the string, and I can't figure out why. I thought it has something to do with where I'm assigning the null terminator, but changing that didn't help. Any help would be appreciated. Thanks!
char* findKey(char lineBuffer, int columnNumber ){
char tempArray[strlen(lineBuffer)+2];
int commasCounted = 0;
int i =0;
for(i = 0; i < strlen(lineBuffer) - 1; i++){
if (commasCounted == columnNumber){
commasCounted = i;
break;
}
if (lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
i++;
}
}
if (lineBuffer[i] == ','){
commasCounted++;
}
}
if(lineBuffer[commasCounted] == ','){
tempArray[0] = '0';
tempArray[1] = '0';
tempArray[2] = '0';
tempArray[3] = '0';
tempArray[4] = '';
}else{
int j = 0;
for(i = commasCounted; i < strlen(lineBuffer) - 1; i++){
if(lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
tempArray[j] = lineBuffer[i];
i++;
j++;
}
break;
}else if(lineBuffer[i] == ','){
break;
}else
tempArray[j] = lineBuffer[i];
j++;
}
tempArray[j] = '';
}
char* tempString = strtok(tempArray, "n");
//printf("tempString before returning in findKey: %sn", tempString); //testing
return tempString;
}
The CSV file can have certain columns wrapped in quotes, which is why there are some checks for quotes in there. This gets passed the string to check, and the column that holds the information. So, for example:
Passing in this for lineBuffer:
30,beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstandoh
And a 1 for columnNumber
Results in this being returned:
beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstando
c arrays string char
|
show 12 more comments
I'm trying to parse through a line of a CSV file and pull out the desired value that I want. However, my function is cutting off the last character in the string, and I can't figure out why. I thought it has something to do with where I'm assigning the null terminator, but changing that didn't help. Any help would be appreciated. Thanks!
char* findKey(char lineBuffer, int columnNumber ){
char tempArray[strlen(lineBuffer)+2];
int commasCounted = 0;
int i =0;
for(i = 0; i < strlen(lineBuffer) - 1; i++){
if (commasCounted == columnNumber){
commasCounted = i;
break;
}
if (lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
i++;
}
}
if (lineBuffer[i] == ','){
commasCounted++;
}
}
if(lineBuffer[commasCounted] == ','){
tempArray[0] = '0';
tempArray[1] = '0';
tempArray[2] = '0';
tempArray[3] = '0';
tempArray[4] = '';
}else{
int j = 0;
for(i = commasCounted; i < strlen(lineBuffer) - 1; i++){
if(lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
tempArray[j] = lineBuffer[i];
i++;
j++;
}
break;
}else if(lineBuffer[i] == ','){
break;
}else
tempArray[j] = lineBuffer[i];
j++;
}
tempArray[j] = '';
}
char* tempString = strtok(tempArray, "n");
//printf("tempString before returning in findKey: %sn", tempString); //testing
return tempString;
}
The CSV file can have certain columns wrapped in quotes, which is why there are some checks for quotes in there. This gets passed the string to check, and the column that holds the information. So, for example:
Passing in this for lineBuffer:
30,beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstandoh
And a 1 for columnNumber
Results in this being returned:
beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstando
c arrays string char
1
you're returning a tokenized string out of a temporary / local string: that's undefined behaviour
– Jean-François Fabre♦
Nov 16 '18 at 19:53
1
Are you doing this to learn, or is this part of a real application? For the latter, you would be better off using a pre-written CSV library.
– Barmar
Nov 16 '18 at 19:53
@Barmar To learn
– Locke
Nov 16 '18 at 19:54
have you tried to duplicate the line:char* tempString = strdup(strtok(tempArray, "n"));
– Jean-François Fabre♦
Nov 16 '18 at 19:54
I thought this was python, my first comment now removed was "can't you use thecsv
module? lol... There are probably good examples of this here. Study them.
– Jean-François Fabre♦
Nov 16 '18 at 19:55
|
show 12 more comments
I'm trying to parse through a line of a CSV file and pull out the desired value that I want. However, my function is cutting off the last character in the string, and I can't figure out why. I thought it has something to do with where I'm assigning the null terminator, but changing that didn't help. Any help would be appreciated. Thanks!
char* findKey(char lineBuffer, int columnNumber ){
char tempArray[strlen(lineBuffer)+2];
int commasCounted = 0;
int i =0;
for(i = 0; i < strlen(lineBuffer) - 1; i++){
if (commasCounted == columnNumber){
commasCounted = i;
break;
}
if (lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
i++;
}
}
if (lineBuffer[i] == ','){
commasCounted++;
}
}
if(lineBuffer[commasCounted] == ','){
tempArray[0] = '0';
tempArray[1] = '0';
tempArray[2] = '0';
tempArray[3] = '0';
tempArray[4] = '';
}else{
int j = 0;
for(i = commasCounted; i < strlen(lineBuffer) - 1; i++){
if(lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
tempArray[j] = lineBuffer[i];
i++;
j++;
}
break;
}else if(lineBuffer[i] == ','){
break;
}else
tempArray[j] = lineBuffer[i];
j++;
}
tempArray[j] = '';
}
char* tempString = strtok(tempArray, "n");
//printf("tempString before returning in findKey: %sn", tempString); //testing
return tempString;
}
The CSV file can have certain columns wrapped in quotes, which is why there are some checks for quotes in there. This gets passed the string to check, and the column that holds the information. So, for example:
Passing in this for lineBuffer:
30,beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstandoh
And a 1 for columnNumber
Results in this being returned:
beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstando
c arrays string char
I'm trying to parse through a line of a CSV file and pull out the desired value that I want. However, my function is cutting off the last character in the string, and I can't figure out why. I thought it has something to do with where I'm assigning the null terminator, but changing that didn't help. Any help would be appreciated. Thanks!
char* findKey(char lineBuffer, int columnNumber ){
char tempArray[strlen(lineBuffer)+2];
int commasCounted = 0;
int i =0;
for(i = 0; i < strlen(lineBuffer) - 1; i++){
if (commasCounted == columnNumber){
commasCounted = i;
break;
}
if (lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
i++;
}
}
if (lineBuffer[i] == ','){
commasCounted++;
}
}
if(lineBuffer[commasCounted] == ','){
tempArray[0] = '0';
tempArray[1] = '0';
tempArray[2] = '0';
tempArray[3] = '0';
tempArray[4] = '';
}else{
int j = 0;
for(i = commasCounted; i < strlen(lineBuffer) - 1; i++){
if(lineBuffer[i] == '"'){
i++;
while(lineBuffer[i] && lineBuffer[i] != '"'){
tempArray[j] = lineBuffer[i];
i++;
j++;
}
break;
}else if(lineBuffer[i] == ','){
break;
}else
tempArray[j] = lineBuffer[i];
j++;
}
tempArray[j] = '';
}
char* tempString = strtok(tempArray, "n");
//printf("tempString before returning in findKey: %sn", tempString); //testing
return tempString;
}
The CSV file can have certain columns wrapped in quotes, which is why there are some checks for quotes in there. This gets passed the string to check, and the column that holds the information. So, for example:
Passing in this for lineBuffer:
30,beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstandoh
And a 1 for columnNumber
Results in this being returned:
beforeyoustartedgackinyouusedtohaveabrainbutnowyoudontgeteventhesimpliesofthingsdrawalittlepictureevenusemyhandstrytoexplainbutyoujustdontunderstando
c arrays string char
c arrays string char
edited Nov 16 '18 at 20:00
Barmar
437k36260365
437k36260365
asked Nov 16 '18 at 19:48
LockeLocke
528
528
1
you're returning a tokenized string out of a temporary / local string: that's undefined behaviour
– Jean-François Fabre♦
Nov 16 '18 at 19:53
1
Are you doing this to learn, or is this part of a real application? For the latter, you would be better off using a pre-written CSV library.
– Barmar
Nov 16 '18 at 19:53
@Barmar To learn
– Locke
Nov 16 '18 at 19:54
have you tried to duplicate the line:char* tempString = strdup(strtok(tempArray, "n"));
– Jean-François Fabre♦
Nov 16 '18 at 19:54
I thought this was python, my first comment now removed was "can't you use thecsv
module? lol... There are probably good examples of this here. Study them.
– Jean-François Fabre♦
Nov 16 '18 at 19:55
|
show 12 more comments
1
you're returning a tokenized string out of a temporary / local string: that's undefined behaviour
– Jean-François Fabre♦
Nov 16 '18 at 19:53
1
Are you doing this to learn, or is this part of a real application? For the latter, you would be better off using a pre-written CSV library.
– Barmar
Nov 16 '18 at 19:53
@Barmar To learn
– Locke
Nov 16 '18 at 19:54
have you tried to duplicate the line:char* tempString = strdup(strtok(tempArray, "n"));
– Jean-François Fabre♦
Nov 16 '18 at 19:54
I thought this was python, my first comment now removed was "can't you use thecsv
module? lol... There are probably good examples of this here. Study them.
– Jean-François Fabre♦
Nov 16 '18 at 19:55
1
1
you're returning a tokenized string out of a temporary / local string: that's undefined behaviour
– Jean-François Fabre♦
Nov 16 '18 at 19:53
you're returning a tokenized string out of a temporary / local string: that's undefined behaviour
– Jean-François Fabre♦
Nov 16 '18 at 19:53
1
1
Are you doing this to learn, or is this part of a real application? For the latter, you would be better off using a pre-written CSV library.
– Barmar
Nov 16 '18 at 19:53
Are you doing this to learn, or is this part of a real application? For the latter, you would be better off using a pre-written CSV library.
– Barmar
Nov 16 '18 at 19:53
@Barmar To learn
– Locke
Nov 16 '18 at 19:54
@Barmar To learn
– Locke
Nov 16 '18 at 19:54
have you tried to duplicate the line:
char* tempString = strdup(strtok(tempArray, "n"));
– Jean-François Fabre♦
Nov 16 '18 at 19:54
have you tried to duplicate the line:
char* tempString = strdup(strtok(tempArray, "n"));
– Jean-François Fabre♦
Nov 16 '18 at 19:54
I thought this was python, my first comment now removed was "can't you use the
csv
module? lol... There are probably good examples of this here. Study them.– Jean-François Fabre♦
Nov 16 '18 at 19:55
I thought this was python, my first comment now removed was "can't you use the
csv
module? lol... There are probably good examples of this here. Study them.– Jean-François Fabre♦
Nov 16 '18 at 19:55
|
show 12 more comments
1 Answer
1
active
oldest
votes
You're never copying the last character of the line because you have i < strlen(lineBuffer) - 1
in the for
loop condition. Change that to i < strlen(lineBuffer)
.
You also need to make a copy of the string before returning, you can't return a local array in C:
return strdup(tempString);
This also means that the caller needs to free this string when they're done with it, since strdup()
allocates memory dynamically. Alternatively, you could use malloc()
to allocate tempArray()
in the first place, instead of declaring a local array.
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: doesstrdup
allocate memory dynamically behind the scenes?
– Locke
Nov 16 '18 at 20:19
Yes,strlen()
returns the index of the null terminator. That's why you use<
in the condition, to stop on the character before that, which is the last real character. If you were using<=
then it would be correct to subtract 1.
– Barmar
Nov 16 '18 at 20:22
Yes,strdup()
allocates memory dynamically. That's why you need to free it.
– Barmar
Nov 16 '18 at 20:22
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without usingstrdup
. If it's undefined behavior, shouldn't it be breaking in this case?
– Locke
Nov 16 '18 at 20:23
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
|
show 2 more comments
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%2f53344450%2flosing-last-character-in-string-when-reading-a-value-from-a-line-in-a-csv%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're never copying the last character of the line because you have i < strlen(lineBuffer) - 1
in the for
loop condition. Change that to i < strlen(lineBuffer)
.
You also need to make a copy of the string before returning, you can't return a local array in C:
return strdup(tempString);
This also means that the caller needs to free this string when they're done with it, since strdup()
allocates memory dynamically. Alternatively, you could use malloc()
to allocate tempArray()
in the first place, instead of declaring a local array.
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: doesstrdup
allocate memory dynamically behind the scenes?
– Locke
Nov 16 '18 at 20:19
Yes,strlen()
returns the index of the null terminator. That's why you use<
in the condition, to stop on the character before that, which is the last real character. If you were using<=
then it would be correct to subtract 1.
– Barmar
Nov 16 '18 at 20:22
Yes,strdup()
allocates memory dynamically. That's why you need to free it.
– Barmar
Nov 16 '18 at 20:22
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without usingstrdup
. If it's undefined behavior, shouldn't it be breaking in this case?
– Locke
Nov 16 '18 at 20:23
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
|
show 2 more comments
You're never copying the last character of the line because you have i < strlen(lineBuffer) - 1
in the for
loop condition. Change that to i < strlen(lineBuffer)
.
You also need to make a copy of the string before returning, you can't return a local array in C:
return strdup(tempString);
This also means that the caller needs to free this string when they're done with it, since strdup()
allocates memory dynamically. Alternatively, you could use malloc()
to allocate tempArray()
in the first place, instead of declaring a local array.
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: doesstrdup
allocate memory dynamically behind the scenes?
– Locke
Nov 16 '18 at 20:19
Yes,strlen()
returns the index of the null terminator. That's why you use<
in the condition, to stop on the character before that, which is the last real character. If you were using<=
then it would be correct to subtract 1.
– Barmar
Nov 16 '18 at 20:22
Yes,strdup()
allocates memory dynamically. That's why you need to free it.
– Barmar
Nov 16 '18 at 20:22
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without usingstrdup
. If it's undefined behavior, shouldn't it be breaking in this case?
– Locke
Nov 16 '18 at 20:23
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
|
show 2 more comments
You're never copying the last character of the line because you have i < strlen(lineBuffer) - 1
in the for
loop condition. Change that to i < strlen(lineBuffer)
.
You also need to make a copy of the string before returning, you can't return a local array in C:
return strdup(tempString);
This also means that the caller needs to free this string when they're done with it, since strdup()
allocates memory dynamically. Alternatively, you could use malloc()
to allocate tempArray()
in the first place, instead of declaring a local array.
You're never copying the last character of the line because you have i < strlen(lineBuffer) - 1
in the for
loop condition. Change that to i < strlen(lineBuffer)
.
You also need to make a copy of the string before returning, you can't return a local array in C:
return strdup(tempString);
This also means that the caller needs to free this string when they're done with it, since strdup()
allocates memory dynamically. Alternatively, you could use malloc()
to allocate tempArray()
in the first place, instead of declaring a local array.
edited Nov 16 '18 at 20:23
answered Nov 16 '18 at 20:13
BarmarBarmar
437k36260365
437k36260365
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: doesstrdup
allocate memory dynamically behind the scenes?
– Locke
Nov 16 '18 at 20:19
Yes,strlen()
returns the index of the null terminator. That's why you use<
in the condition, to stop on the character before that, which is the last real character. If you were using<=
then it would be correct to subtract 1.
– Barmar
Nov 16 '18 at 20:22
Yes,strdup()
allocates memory dynamically. That's why you need to free it.
– Barmar
Nov 16 '18 at 20:22
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without usingstrdup
. If it's undefined behavior, shouldn't it be breaking in this case?
– Locke
Nov 16 '18 at 20:23
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
|
show 2 more comments
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: doesstrdup
allocate memory dynamically behind the scenes?
– Locke
Nov 16 '18 at 20:19
Yes,strlen()
returns the index of the null terminator. That's why you use<
in the condition, to stop on the character before that, which is the last real character. If you were using<=
then it would be correct to subtract 1.
– Barmar
Nov 16 '18 at 20:22
Yes,strdup()
allocates memory dynamically. That's why you need to free it.
– Barmar
Nov 16 '18 at 20:22
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without usingstrdup
. If it's undefined behavior, shouldn't it be breaking in this case?
– Locke
Nov 16 '18 at 20:23
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: does
strdup
allocate memory dynamically behind the scenes?– Locke
Nov 16 '18 at 20:19
That was it, the for loop condition. Thank you so much. Some further questions: I thought strlen(lineBuffer) refers to the last space in the string, the null terminator? Is that not the case? Also: does
strdup
allocate memory dynamically behind the scenes?– Locke
Nov 16 '18 at 20:19
Yes,
strlen()
returns the index of the null terminator. That's why you use <
in the condition, to stop on the character before that, which is the last real character. If you were using <=
then it would be correct to subtract 1.– Barmar
Nov 16 '18 at 20:22
Yes,
strlen()
returns the index of the null terminator. That's why you use <
in the condition, to stop on the character before that, which is the last real character. If you were using <=
then it would be correct to subtract 1.– Barmar
Nov 16 '18 at 20:22
Yes,
strdup()
allocates memory dynamically. That's why you need to free it.– Barmar
Nov 16 '18 at 20:22
Yes,
strdup()
allocates memory dynamically. That's why you need to free it.– Barmar
Nov 16 '18 at 20:22
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without using
strdup
. If it's undefined behavior, shouldn't it be breaking in this case?– Locke
Nov 16 '18 at 20:23
Ahh, got it. Thank you. One last thing: it seems like the code is working fine without using
strdup
. If it's undefined behavior, shouldn't it be breaking in this case?– Locke
Nov 16 '18 at 20:23
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
@Locke The behaviour of undefined behaviour is undefined.
– Swordfish
Nov 16 '18 at 20:25
|
show 2 more comments
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%2f53344450%2flosing-last-character-in-string-when-reading-a-value-from-a-line-in-a-csv%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
1
you're returning a tokenized string out of a temporary / local string: that's undefined behaviour
– Jean-François Fabre♦
Nov 16 '18 at 19:53
1
Are you doing this to learn, or is this part of a real application? For the latter, you would be better off using a pre-written CSV library.
– Barmar
Nov 16 '18 at 19:53
@Barmar To learn
– Locke
Nov 16 '18 at 19:54
have you tried to duplicate the line:
char* tempString = strdup(strtok(tempArray, "n"));
– Jean-François Fabre♦
Nov 16 '18 at 19:54
I thought this was python, my first comment now removed was "can't you use the
csv
module? lol... There are probably good examples of this here. Study them.– Jean-François Fabre♦
Nov 16 '18 at 19:55