Questions tagged [strtok]

strtok() is a Standard C (ISO 9899:1989) function for splitting a string in tokens. strtok_r() is the thread-safe variant defined by IEEE Std 1003.1:2004 (aka "POSIX").

NAME

strtok, strtok_r - split string into tokens

SYNOPSIS

#include <string.h>

char *strtok(char *restrict s1, const char *restrict s2);
char *strtok_r(char *restrict s, const char *restrict sep,
       char **restrict lasts);
1404 questions
-4
votes
1 answer

Problems with fgets and strtok in C

I need to fill a 2d array with numbers from a string so I am using strtok and fgets to get the string and tokenize it. However if I enter "1 2 3 4 5" and the 2d array's dimensions are 2x2, the 5 never gets assigned to number. I want to check if…
Tirth Rami
  • 271
  • 4
  • 15
-5
votes
1 answer

strtok and replacing a character in a string

i need help finding my mistake. Write a program that reads a multi-line CSV file and reads any number of values ​​,,..., per line. Example file1.csv: 4,10,9,13 -1 7,13,100 After reading in, the values ​​are to be output in the format…
manuel
  • 1
  • 2
-5
votes
1 answer

Get value from a CSV table in C

I have made a matrix in MatLab and exported it as a CSV. I don't really know how to use it in my C code though. For example, my table looks like this (allthough much bigger and more complicated values): Height/Angle, 50, 550, 1050, 1550, 2050 5,…
-5
votes
1 answer

strtok deletes my string except the first token

i have linked list with songs details and want to compare two song names... the additional task is to compare them by having more similar words than different words...i use strtok to get it word by word and then check if the current word is…
-5
votes
1 answer

Incorrect behavior of a pointer in function in C

I have a problem with the following program. The main function calls the function returnArrayOfWords(arrS1, &ptrArray1) twice. On the first call, the array is parsed perfectly, and afterward the pointer always points to the first word. On the other…
-5
votes
1 answer

strtok function c explain

This is an example of the strtok function... I need to an explanation for this block: while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " "); } return 0; especially pch = strtok (NULL, " "); #include #include…
-5
votes
7 answers

Complex algorithm to extract numbers/number range from a string

I am working on a algorithm where I am trying the following output: Given values/Inputs: char *Var = "1-5,10,12,15-16,25-35,67,69,99-105"; int size = 29; Here "1-5" depicts a range value, i.e. it will be understood as "1,2,3,4,5" while the values…
Amrit
  • 2,295
  • 4
  • 25
  • 42
-5
votes
3 answers

strtok not working as expected

I tried to write a function that gets a pointer to array of char, reads a string from the user and remove all spaces in the start of the string till the first char that is not string appear. Finally return the copy of the string without space/s in…
Yuval
  • 1,721
  • 4
  • 16
  • 15
-7
votes
1 answer

Parsing user input. C

I am trying to create a program that runs certain commands ( Pali() is the command ) for example, when the user types in Pali(bob) the program checks if the word inside the () is a palindrome. Also, the command Pali() must be exactly typed out like…
Sherin
  • 13
  • 5
1 2 3
93
94