Previously stored strings are replaced by fgets

I'm reading records from a CSV file using fgets() to read the file one line at a time, and strtok() to parse the fields in each line. I'm encountering a problem where fgets() overwrites a string that was previously written, in favor of the new string

strtok pointer takes delimiter value

I wanted to test strtok with multiple delimeters, and I wrote the code below, but after printing the first token, token takes the delimeter value instead that of the next word in the string. #include <string.h> int main(int argc, char *argv[]) { cha

Table of structures - C bad value

I'm facing a quite interesting problem in C. So I have a struct which looks like this: struct Question { int year; char* month; char* day; char* hour; char* minute; char* second; char* question; int answerCount; char* answers[1024]; } questions[100];

Why strtok () does not choose the '?' character of the line?

Here below is my code in codeblocks version 13:12. It is not commented because I laid it down quick to ask here having lost my hair! My concern is that I expect my char * target to be /cat.html?name=image but I only get /cat.html! #include <stdio.h>

C Delete the last character of the string

I want to delete last character in string first, i use strtok function My Input is : "Hello World Yaho" I use " " as my delimeter My expectation is this Hell Worl Yah But the actual output is this Hello Worl Yaho How can I solve this p

Uses the value of token (strtok) in function c

I got a bit confused using token, say if: int main(void) { char input[100]; fgets(input, 100, stdin); char * token = strtok(input, " "); char * height = strtok(NULL, " "); char * width = strtok(NULL, " "); if (height > 9 &

how to use strtok to mark an expression using c ++

i need to tokenize an mathematical expression using strok..i have done something but i cannot get delimiters to my vector when i run the code i get 2x 4y 6 3 this output how can i get delimiters to my vector and how can i get my output like this 2x +

Implementing the split function in C

I'm trying to write a C function that is similar to split in Java. When I do what I do at main, instead of add function, it works perfectly. But I couldn't understand why it does not work with add function. #include <stdio.h> #include <string.h&g

Divide a string into a table file in c

I'm new to programming,and I have a small problem. I have a file named questions.txt containing a string of questions, I want to read the string from the file then split it into array with each question having an index, for example a[i] = "Question i

Char * bed in one character (in C)

I'm going to do my best to explain this, but if you can't quite understand what my problem is then feel free to ask for clarification :) Working on a problem for a tutorial, where a plaintext message can be encrypted or a ciphertext message can be de

Access violation when calling strtok (); C ++

I'm having trouble with this bit of code: char KernelFS::doesExist(char* fname){ char part; char name[8]; char ext[3]; char* token; token = strtok(fname, "\\"); strncpy(&part, token, 1); token = strtok(fname, "\\"); strncpy(name, t

2nd call to strtok () returns null

I'm at the top of a while loop in the client file for a client/server communication. The client gets user input (input) and I need to strtok it into cmd and cmd2 for my ifs to work. Say the user puts in "get lname" (this is a good command for th

problem with strcmp () in C

char* mystr = calloc(25, sizeof(char)); fgets(mystr, 25, stdin); // I enter "6 7 *" in here, without the quotes char* tok; tok = strtok(mystr, " "); while (tok != NULL) { if(strcmp(tok, "*") == 0) //It never meets this condit

How to use strtok ()

I'm writing a C program to study the usage of strtok() usage. Here is my code: #include<stdio.h> #include<string.h> main() { char abc[100] = "ls &"; char * tok; tok = strtok(abc, " "); while(tok!=NULL) { printf("%s

Get the length of a chain token

C Programming: I'm attempting to get the length of each word inside a string, but having massive troubles and get a segmentation fault no matter what method I use. I was originally trying to use just "strlen(pstr)" but that caused segmentation f

strtok and (null) in C

I am trying to use strtok to separate a string by a comma. The line looks like this: A:K149, A:N171, A:T172 I am using the following code. pch=strtok(line,","); printf("%s\n",pch); while(pch!=NULL){ pch=strtok(NULL,", "); pri

Break a chain into separate parts

//PROBLEM NUMBER 2 //how to store word from pointer2char into wordList array? New_sentence is an array holding a string (sentence inputted from user). pointers2char is a pointer array that is supposed to hold pointers to each word of New_sentence. Wh

Analyze the string with strtok ()

I'm trying to parse this line Completion_Time_Stamp = [email protected]:10:22(Eastern Daylight Time) and put the name in one variable and value in another token[0] = strtok(buf, " = "); // first token if (token[0]) // zero if line is blank { for (n

strtok and escape characters

I'm working on a shell in C that uses strtok on the space char (' ') to create a list of arguments from the user input. For example, strtok 'ls foo bar' creates a char* with three elements: ls, foo, bar. My question is, how do I detect escape-space?

using getline and strtok together in a loop

I am new to C, and trying to implement whoami, as an exercise to myself. I have following code: #define _POSIX_SOURCE #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <string.h> // strtok int str_to_int(const

Analyze a document, C

I need to parse a document in C language. I was about to use the strtok function but I don't know if it's the best method or if just a token system is enough (searching for \n, space etc). The structure of each line of the document is : element \n el

Abnormal behavior to handle text files in C

I'm trying to simulate the behavior of a DNS server, which I have a DB named hosts.txt containing machine_names/IP_addresses, for example: equipo_00/ sala_oeste_01/ sala_oeste_02/ sala_oeste_03/ MEMFIS_04/2

Structures, strtok, segmentation error

I'm trying to make a program with structs and files. The following is just a part of my code(it;s not the entire program). What i'm trying to do is: ask the user to write his command. eg. delete John eg. enter John James 5000 ipad purchase. The probl

strtok will not accept: char * str

strtok wont work correctly when using char *str as the first parameter (not the delimiters string). Does it have something to do with the area that allocates strings in that notation? (which as far as i know, is a read-only area). thanks in advance e

strtok and function call

I have this extremely strange behavior coming : In the below code: If I comment the call to MyLogger then everything works fine that is I get the sTempNr tokenized and 4 tokens are printed . But if I uncomment the call to MyLogger for logging then on

Is there an equivalent of the split () function of Perls in C?

I'm trying to split real numbers in a C program using the decimal point as the delimter such that such that say, 1234.56 yields (int) whole_num = 1234 (int) fraction = 56 Any ideas how I can go about doing this? Its been a loooong while since I mucke