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...
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...
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...
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 ...
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...
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...
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(...
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 ...
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...
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...
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...
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...
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...
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;
...
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...
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...
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.
4
Why does the compiler still warn me about unsafe strtok even after I define _CRT_SECURE_NO_WARNINGS?
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...
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(...
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 ...
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...
4
Solved
Whats the use of function strtok() in PHP? How is better than other string function doing the same thing?
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...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.