All Questions
150 questions
2
votes
1
answer
108
views
Is there any way to seprate strings to substrings we choose? like: sin(log(10))
Is there any way to submerge a string and put it into an array like:
y = sin(log(tan(x))) -> {"y", "=", "sin", "(", ...}
no blank space matters like: sin(x) =...
3
votes
1
answer
126
views
String split function in C
I'm trying to write a string splitting function in C, much resembling ones already available in other higher-level languages.
In order to save myself the hassle of constant memory (re-)allocation with ...
0
votes
3
answers
194
views
C - split string using multiple delimiters in C
How to write a function that split a string using multiples delimiters, which could be char like ',' and could be string like "or".
For example, for the string char * string = "a or b ...
-1
votes
1
answer
183
views
SOLVED-what am I doing wrong that strtok does right in splitting a string
Previous question was : what am I doing wrong that strtok does right in splitting a string. Also separating the strtok to a function suddenly doesn't produce correct result?
This is the first time ...
-1
votes
1
answer
37
views
C String spliting into array, bad behaviour when string is not supposed to be split
when input has "|" the string splits normally, when str does not have "|" it seg faults
char **cmds;
if (strchr(input, '|'))
cmds = split(input,'|');
else
cmds[0] = strdup(...
1
vote
2
answers
188
views
Splitting a string into substrings using C
I'm trying to make a program that splits the string based on a specific character.
Data Structure used:
typedef struct pieces {
char **members;
size_t len;
} pieces;
Function declarations:
...
1
vote
3
answers
149
views
Why C dosen't split correctly arrays?
I have an array of 64 characters, which I need to divide into two parts, the left part of 32 characters and the right part, also 32 characters.
char *IP_M; // 64 characters array
char L[32]; // left ...
0
votes
1
answer
92
views
Using strtok to split the string and concatenating additional string - could it be done in a more efficient way?
I have a string A,B which needs to be modified to Av1.0,Bv1.0, where 1 and 0 are stored in respective variables v1, v2
I came up with a following logic but it seems a bit too verbose. Perhaps there's ...
0
votes
1
answer
388
views
How to split char pointer array into two char pointer arrays
My question is how can I split argv into two parts and store the parts in two variables.
I want my program to get parameters then a delimiter and then again parameters like this:
./program parameter1 ...
0
votes
1
answer
94
views
C split specific File input into variables
I'm making phone book assignment.
I have to get data from delivered file that is given in specific format.
Name | Surname | Phone number
I'm using code below :
while(!feof(file)){
int ...
1
vote
4
answers
878
views
splitting string and counting tokens in c
I have a text file that contains multiple strings that are different lengths that I need to split into tokens.
Is it best to use strtok to split these strings and how can I count the tokens?
Example ...
0
votes
1
answer
304
views
Reading from csv file in C causing input to not print
I am trying to read data from a csv file input below:
0, 0
5, 0
7, 0
This input is supposed to be x and y coordinates where x= 0 and y =0 and x=5 and y=5 and so on....
What i have tried
I am trying ...
0
votes
3
answers
748
views
how to split a string into 2 bytes by 2 bytes
How to split a string into 2 bytes by 2 bytes.I want to get time information as integer value from string.
char buffer[10]= "101507";
int hour = < 10
int min = < 15
int sec = < 07
0
votes
0
answers
112
views
How to extract coefs and powers of polynomial from a string in C?
The exact question in the header.
e.g. 1*x^5-10*x^3+3*x^2+5
I'm trying to use strtok:
char str[] = "1*x^5-10*x^3+3*x^2+5";
char *token = strtok(str, "*x^+-");
while (token != NULL)...
0
votes
1
answer
61
views
C function to split complex strings
Hi Everyone I need to split a string like,
["myroot", "prod1" , ["prod2", "a", "b","c"], "prod3", ["ext", "ali&...
0
votes
0
answers
178
views
split string and put words into an array
I am working on a function which allows to split a character string and to place each word in an array. the last cell of the array must return a null. the separator character must be a space, a ...
0
votes
0
answers
82
views
strtok() behavior that I don't understand
I'm hoping to use strtok() in a C program I'm writing. I was trying to fiddle with it a little to jog my memory with it, and get back in practice with it, and ran into some behavior that I can't ...
0
votes
1
answer
271
views
split string by certain character in c program
I have a string "Hello;World" and I am trying to use a c program to split this string into the components Hello and World basically spliting the string at the ;.
Below is the code I am for ...
0
votes
2
answers
1k
views
split a string into letters and digits in c
I want to write a code to split the numbers and characters in this pattern by finding finding the position of first digit and alphabet and using strcpy and strncpy in c
input:
ATL1203S14
output:
...
-1
votes
1
answer
27
views
split string into different parts without spaces and dividers
I have a string 2020122812.txt which I want to be able to extract for numbers from which are a four digit year, 2 digit month, 2 digit day and 2 digit hour.
Below is a snippet of my code in which I ...
0
votes
1
answer
75
views
Split a string into token in C
struct string {
size_t length;
size_t allocated;
char* data;
};
string* strCreate(char* str) {...}
string* strSubstring(string* str, size_t pos, size_t len) {...}
char* strGet(string* ...
0
votes
1
answer
136
views
Tokenize string by space and assign multiple of tokenized of them into one string in C
I have some data in a .csv file and each line belongs to one driver. What I want to do is to read each line of the CSV file and then split it into words. Generally each part one line data is separated ...
1
vote
2
answers
128
views
How to deal with the return value which are new line and special symbol in C?
Here is a newbie's question, I have a return value which have two new line and some special symbol.
But I only want to get the specific part of above-mentioned value.
There is a simple example that ...
0
votes
1
answer
209
views
Can't figure out how strchr works in C
I have this piece of code that is suppose to split a string depending on the delimiter. It seems to work when the delimiter is '\0' (null character) but when I try to make it work with '\n' (newline) ...
0
votes
1
answer
504
views
How split a string in c with comma
I created a function to split a string with comma.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char splitted_line[8][50];
void split(char *line){
printf(&...
0
votes
0
answers
116
views
strtok with reading lines from file in C
Reading cities and their coordinates from a file and calculating their distance to the point (lat1;lat2) I combined fgets with strtok like this:
const char sep[]=";";
char data[99];
char *token;
int ...
1
vote
4
answers
670
views
I want to split a string into two strings in C
I want to split a string by the comma and separate the first number in the string into its own new string, the rest of the string I want to keep together.
So far I have tried this by using strtok() ...
1
vote
1
answer
71
views
How can I use sscanf with white space?
I am trying to split a string into some pieces, but it is not doing this properly. Here is my code.
int main(void){
char point[2][2];
char *try="Distance P1 P2 // Prints the distance between ...
1
vote
1
answer
409
views
Comparing the first and third character of a string
I have a .txt file that contains data in this format:
AxCs: 0.9467,
FyHd: 0.9489,
AzCf: 0.78973,
DhBh: 0.8874,
JyLt: 0.64351,
AxCb: 0.8743,
and so on...
I have a C program which ...
0
votes
1
answer
138
views
Extract numerical values from a string and average them
I have a .txt file that contains data in this format:
xxxx: 0.9467,
yyyy: 0.9489,
zzzz: 0.78973,
hhhh: 0.8874,
yyyy: 0.64351,
xxxx: 0.8743,
and so on...
Let's say that my C program ...
2
votes
5
answers
327
views
Breaking up a string into a list of tokens using another string as a delimiter?
Let's say I have this string:
char *myTestString = "Hello AND test AND test2";
I want to break this down into the set { Hello, test, test2 }, which I can finally iterate over.
Or I have
char *...
-4
votes
1
answer
263
views
How to delete last part of string in C
I need a certain part of the string for example I have
folder1/folder2/folder3/folder4
and I don't want folder4 in my new string so it should be like
folder1/folder2/folder3
any help would be ...
1
vote
1
answer
219
views
I am getting an error message when trying to split a string and put them into an array
I am trying to split the user's input and put each delimiter in an array.
For some reasons, with the code I have here, I get an error message:
called object type 'char *[10]' is not a function or ...
0
votes
0
answers
455
views
How to correctly use strsep() to parse an array?
I'm trying to implement a function that takes a string to parse and delimiter string as inputs, then returns a char array containing these parsed elements including empty chars if two delimiters are ...
3
votes
2
answers
85
views
Try to split string but got messy substrings
I try to split one string to 3-gram strings. But turns out that the resulting substrings were always messy. The length and char ** input... are needed, since I will use them as args later for python ...
1
vote
2
answers
65
views
Appending words to an array based on a separator
I am trying to break up the sentence "once upon a time" into an array of words. I am doing this via a for loop, detecting three conditions:
It's the end of the loop (add the \0 and break);
It's the ...
2
votes
1
answer
184
views
How can I efficiently split strings and copy substrings in C?
I have used to split C strings by many means: strstr, strsep, strtok, strtok_r...Here is a case where I have a delimiter and I want to split the string. Having only done so in languages such as Java, ...
2
votes
3
answers
1k
views
Is there a way to split an array of strings into subarray of strings on token
Basically, is there any way to split an array of strings into arrays of strings before and after a token ("|") in C.
An example is shown below.
char *input[] = {"hello","I","am","|","a","cool","|","...
3
votes
3
answers
454
views
Need help to split a string by delimiter (and keep the delimiter in the token list)
I want to split a string by a delimiter and keep the delimiter in the token list
I have a function that do the same thing as strtok but with a string delimiter (instead of a set of chars) but it ...
2
votes
3
answers
157
views
Splitting string by delimiter does not split correctly
I have a function that has to spilt a line read from file into words by some delimiters (delimiters check is made by another function) but my code splits the string by delimiters which are not ...
1
vote
3
answers
67
views
Why is the string loop is being ignored?
I am new to the programming world and I'm trying to make a string split by using a loop that should split all characters separately but it's being ignored and basically ends with showing the input of ...
-2
votes
1
answer
95
views
Spliting a string
I'm trying to make a program that should split a string in half but so far the program is printing out random letters when I want it to read what the user writes and use the string to split it in half....
0
votes
1
answer
2k
views
Tokenizing an array of string in c
I'm new to programing and for the life of me I can't figure out this problem. I'm trying to create a function that tokenizes a string taking space as the delimiter and a pointer to the string and the ...
-3
votes
1
answer
6k
views
How strsep works in C?
I'm creating a program that when launched takes in input a command and some arguments with scanf and calls execvp using those arguments.
I'm doing this with strsep.
I store the string in an array (...
0
votes
0
answers
42
views
How can I split strings from file into smaller strings in C? [duplicate]
I have a file which looks like this:
text1, number, text2, text3,
text1, number, text2, text3,
...
I'd like to put all of these stuff into struct array:
struct myStruct {
char string1[50];
...
0
votes
1
answer
74
views
Splitting a long string
I have an archive results.csv and I need to read the first two lines of this archive, split the second one and print them out on output.txt. Somehow it's not printing anything, yet I don't know the ...
0
votes
2
answers
1k
views
How to split a string at the first space
I have a string of numbers like this:
160 01 11 12 33 44 44 ...
and I want to split from the start until the first space like this:
160 | 01 11 12 33 44 44....
For example I could put the string ...
0
votes
2
answers
1k
views
C Convert comma separated string to array
I have an archive with comma separated string I want to slip every line into 2 arrays: v[i].date and v[i].value.
However, when I run the code it shows random values for the arrays.
Is there anything I ...
0
votes
1
answer
776
views
Why no split function in C? [closed]
There is no Standard function in C to take a string, break it up at whitespace
or other delimiters, and create an array of pointers to char, in one step.
If you want to do that sort of thing, you have ...
0
votes
1
answer
2k
views
Split a string without delimiter C
I have a string of 256 characters and I would like to split it in 64 strings of 4 characters in c, but I do not have delimiters, is there any function to do so?
I have the following code:
char ...