Questions tagged [strsep]

Questions involving the use of the BSD strsep() function.

strsep() is a function originating in BSD Unix which operates in a similar manner to the standard C strtok() function. The main difference is that this function may return empty tokens, whereas strtok() returns only non-empty tokens.

56 questions
1
vote
1 answer

Segmentation Fault using strsep reading a csv file

I'm currently trying to read a csv file using strsep but it never passes the first line int main(){ FILE *fp = fopen("users100.csv", "r"); if(!fp){ printf("Erro"); return 0; } char *str; str = (char *)…
1
vote
3 answers

Strsep with Multiple Delimiters: Strange result

I am currently having some strange results when using strsep with multiple delimiters. My delimiters include the TAB character, the space character, as well as > and <. #include #include #include int main() { …
Stephen Wong
  • 177
  • 1
  • 8
1
vote
1 answer

Chained strsep gives segmentation fault - C

I'm trying to create an array of array of strings to prepare them to be shown in a table. So I have a function that returns a buffer string with the list of some scanned wifi access points, and I'm using strsep to split it by "\n" and then again by…
dimoxinil
  • 13
  • 3
1
vote
1 answer

strsep() causing Segmentation fault

I am having a problem with my program in which I am getting a segmentation fault from strsep() which was gotten from GDB and has the error message Program received signal SIGSEGV, Segmentation fault. 0x00002aaaaad64550 in strsep () from…
1
vote
0 answers

C - Strsep() return 0 with negative values

I'm working in a project that use GPS data. I'm trying to get all the data but I've had a lot of problems. The secuence that I recieve is: +CGNSINF: ,,
Javier C
  • 85
  • 1
  • 7
1
vote
1 answer

strtok_r save state behaviour

The correct way to use strtok_r is as follows: char* str = strdup(string); char* save; char* ptr = strtok_r(str, delim, &save); while(ptr) { puts(ptr); ptr = strtok_r(NULL, delim, &save); } When trying to inspect what actually is stored in…
balki
  • 26,394
  • 30
  • 105
  • 151
1
vote
0 answers

Empty lines/characters when reading text file using strsep()

I'm learning C and as a practice, I'm trying read a file with different sets of numbers in each line, and print (or save to a different file) each number per line (also as string). You can see the code here: #include #include…
Nooblhu
  • 552
  • 15
  • 33
1
vote
2 answers

String token from `strsep` not printing (seg fault)

I'm using with a smaller piece of code to test functionality for a larger (beginner) program, but I have a problem displaying the token I've pulled out of a string. I found and used: #include #include int main() { char…
Weaver
  • 145
  • 8
1
vote
1 answer

Parsing String into tokens in C - what's going wrong?

I'm trying to split a string into tokens to create an array of argument parameters. My current implementation is as follows (path is the path to the user-executable file for which optional arguments are being read): // ARG_MAX as defined in…
transiti0nary
  • 493
  • 6
  • 25
1
vote
1 answer

Bus Error Using strsep()

I am attempting to write a series of functions that will take a file name as input (e.g. main.c) and return the file extension using strsep(). When I run the program, I get a bus error whenever the strsep function is called. Here is the code: static…
w m
  • 493
  • 1
  • 5
  • 7
1
vote
1 answer

execvp(): no such file or directory?

For some reason, execvp() doesn't find the commands (like ls, pwd, etc.) in my PATH file, which includes /bin. Since I have a customized terminal alias with ls, I'm using pwd, etc. to test (as well as a fresh Linux machine), but I keep getting this…
CodeSammich
  • 150
  • 1
  • 2
  • 10
1
vote
0 answers

segmentation fault caused by strsep returning null

I am writing a program in C and I want to count how the number of words in the string by dividing the string by the spaces. Here is some of my code while((temp = strsep(&tempInput, " "))!=NULL) { tempArguments[number] = temp; number++; …
Jake Gearhart
  • 297
  • 7
  • 21
1
vote
1 answer

Strange character replacement where it makes no sense (to me)

Sorry for the long sections of code, but I am stumped and need a hand! My specific problem is that when I use my parse method in order to call a "del" event, I get that odd character replacement going on in a line that, as far as I can tell, isn't…
Thanasi Poulos
  • 278
  • 3
  • 16
1
vote
2 answers

Strange output while using strsep and fwrite in C

I was going to make a python program to read from an XML document and use it as a reference while doing an action. However, the XML document would have been tedious to create by hand, so I decided to make a C program to do the bulk of it, excluding…
elder4222
  • 355
  • 2
  • 15
0
votes
1 answer

Error while parsing characters in a char member of a struct with strsep()

I want to parse characters in a char member of a struct with strsep() but got the following error: sep_string_space_on_struct.c:22:26: warning: incompatible pointer types passing 'char (*)[50]' to parameter of type 'char **'…
ecjb
  • 5,169
  • 12
  • 43
  • 79