strtok Questions

6

Solved

I have following string: char str[] = "A/USING=B)"; I want to split to get separate A and B values with /USING= as a delimiter How can I do it? I known strtok() but it just split by one charac...
Afghani asked 22/1, 2016 at 8:53

14

I have a string that I would like to tokenize. But the C strtok() function requires my string to be a char*. How can I do this simply? I tried: token = strtok(str.c_str(), " "); which fails be...
Capacitance asked 14/11, 2008 at 6:14

5

Solved

I have a CSV file containing data such as value;name;test;etc which I'm trying to split by using strtok(string, ";"). However, this file can contain zero-length data, like this: value;;test;etc...
Periwig asked 16/9, 2013 at 12:2

4

Solved

Or rather, how does strtok produce the string to which it's return value points? Does it allocate memory dynamically? I am asking because I am not sure if I need to free the token in the following ...
Shouse asked 3/1, 2014 at 12:56

6

Why do we use NULL in strok() function? while (h != NULL) { h = strtok(NULL, delim); if (hold != NULL) printf("%s", hold); } What does this program do when *h is pointing to a stri...
Festinate asked 4/5, 2014 at 12:45

8

Solved

I am trying to understand why the following snippet of code is giving a segmentation fault: void tokenize(char* line) { char* cmd = strtok(line," "); while (cmd != NULL) { printf ("%s\n",cmd)...
Sun asked 22/1, 2012 at 0:0

16

Solved

Please explain to me the working of strtok() function. The manual says it breaks the string into tokens. I am unable to understand from the manual what it actually does. I added watches on str and...
Antennule asked 8/10, 2010 at 11:23

7

My string is "A,B,C,D,E" And the separator is "," How can I get the remaining string after doing strtok() once, that is "B,C,D,E" char a[] = "A,B,C,D,E"; char * separator = ","; char * b = strtok(...
Lacewing asked 1/11, 2013 at 9:58

1

Solved

fgets() is a safe function to read a line of input, but it stores the new line byte '\n' read from the file in the array if it fits. In many if not most cases, this new line must be removed before ...
Nimbostratus asked 25/1, 2021 at 22:12

3

Solved

How to split a string into an tokens and then save them in an array? Specifically, I have a string "abc/qwe/jkh". I want to separate "/", and then save the tokens into an array. Output will be su...
Calctufa asked 18/3, 2013 at 8:19

5

Solved

I'm trying to convert a char * to uppercase in c, but the function toupper() doesn't work here. I'm trying to get the name of the the value of temp, the name being anything before the colon, in thi...
Assumption asked 3/2, 2016 at 16:5

3

Solved

I am making a program where I need to use a function which stores a tokens of a string in a vector. The function did not work properly so I tried the function on a smaller program. Of course, I use...
Desert asked 25/6, 2020 at 8:16

2

I was trying to parse strings using strtok(); I am trying to parse strings delimited by a semicolon ( ; ). But when I input a string with no semicolons to strtok(), it returns the entire string. Sh...
Offcenter asked 29/11, 2012 at 19:52

4

Solved

How can I use strtok_r instead of strtok to do this? char *pchE = strtok(NULL, " "); Now I'm trying to use strtok_r properly... But sometimes I get problems with the strtol. I have a thread that...
Dichogamy asked 12/4, 2013 at 0:41

3

I'm a beginner at C, please don't bash me. So, I have this function that gets the mask of an "ip/mask" type of string: char *getmask(char n[]) { char x[255] = { 0 }; strcpy(x, n); char *mask; ...
Vaudois asked 31/10, 2016 at 1:39

5

Solved

I am somewhat confused by what happens when you call strtok on a char pointer in C. I know that it modifies the contents of the string, so if I call strtok on a variable named 'line', its content w...
Sanferd asked 15/2, 2011 at 5:42

6

Solved

I'm trying to use this function in a C program that needs to be able to compile in Linux and Windows. At first I tried using strtok_r, but then when I compiled on windows, it complained about the f...
Sublingual asked 26/1, 2012 at 16:29

3

Solved

I'm using strtok to split a string into tokens. Does anyone know any function which actually counts the number of tokens? I have a command string and I need to split it and pass the arguments to e...
Stabilize asked 25/10, 2012 at 23:42

3

Solved

Could someone explain me what differences there are between strtok() and strsep()? What are the advantages and disadvantages of them? And why would I pick one over the other one.
Calutron asked 28/8, 2011 at 2:11

4

I am using Visual Studio Express 2012 for Windows Desktop. I always get error Error C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable depreca...
Heiner asked 10/1, 2014 at 12:16

3

Solved

Code snippet: char str[] = "String1::String2:String3:String4::String5"; char *deli = "::"; char *token = strtok(str,deli); while(token != NULL) { printf("Token= \"%s\"\n", token); token=strtok(...
Alisa asked 24/4, 2015 at 12:47

4

Im trying to take a user input string and parse is into an array called char *entire_line[100]; where each word is put at a different index of the array but if a part of the string is encapsulated ...
Spawn asked 11/3, 2012 at 22:50

3

Solved

Right now I have code set up to divide up my string into tokens with delimiters of ,;= and space. I would also like to include the special characters as tokens. char * cstr = new char [str.length...
Rancidity asked 26/9, 2013 at 19:13

4

Solved

Whats the use of function strtok() in PHP? How is better than other string function doing the same thing?
Belcher asked 27/3, 2010 at 4:43

2

Solved

I hear this from a lot of programmers that the use of strtok maybe deprecated in near future. Some say it is still. Why is it a bad choice? strtok() works great in tokenizing a given string. Does i...
Berey asked 2/6, 2017 at 20:17

© 2022 - 2024 — McMap. All rights reserved.