strsep

Segmentation Fault while trying to parse an excel style .CSV file [C programming]

一笑奈何 提交于 2020-01-06 08:16:51
问题 I've been stuck on this project for the better part of the week and while I have been grinding through syntax errors. The gist of the project is to read through the headers and stopping at a certain column and finding certain characteristics like the min, max and average of the column. However, I am having a tough time with memory allocation for this job. I have been unable to further my code so far because I keep getting an error labeled Segmentation Fault: 11 . The bolded section is what I

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

南楼画角 提交于 2019-12-24 10:23:48
问题 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 <stdio.h> #include <string.h> int main() { char *string, *found; string = strdup ("1/2/3"); printf("Original string: '%s'\n",string); while ((found = strsep(&string,"/")) != NULL ) printf ("%s\n",found); return (0); } and this works fine, prints the tokens one at a time as strings. Then when I try and

What are the differences between strtok and strsep in C

狂风中的少年 提交于 2019-12-17 04:32:13
问题 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. 回答1: From The GNU C Library manual - Finding Tokens in a String: One difference between strsep and strtok_r is that if the input string contains more than one character from delimiter in a row strsep returns an empty string for each pair of characters from delimiter. This means that a program normally should test

What are the differences between strtok and strsep in C

十年热恋 提交于 2019-11-26 20:42:55
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. George Gaál From The GNU C Library manual - Finding Tokens in a String : One difference between strsep and strtok_r is that if the input string contains more than one character from delimiter in a row strsep returns an empty string for each pair of characters from delimiter. This means that a program normally should test for strsep returning an empty string before processing it. One major difference between strtok()