So I'm trying to remove 2 brackets from lines I'm reading from a file. For some reason when I run my program the characters in between the delimeters is removed. for example `greetings pe()ple` would end up as `greetings pe` I'm using a char array of delimiters. `char delimiters[] = " ( )";` Why does strtok delete the characters between the parenthesis?

Member Avatar
Member Avatar
+0 forum 2

the folllowing code i have made but its not catering for the vowels coming together...what should i do in this code to accurately count the number of vowels and count the remining char left in string without vowels as after tokenization only the first token remains in the char array/string being tokenized...plz help`Inline Code Example Here` #include<iostream> #include<cstring> using namespace std; int main() { int vowelcounter=0; char * tokenPtr; char myarray[]="My name is Faraz Saleem Rafai"; char check[]="'a','e','i','o','u'"; tokenPtr=strtok(myarray,check); while(tokenPtr!=NULL) { cout<<tokenPtr<<endl; tokenPtr=strtok(NULL,check); vowelcounter++; } cout<<myarray<<endl; cout<<vowelcounter<<endl; return 0; }

Member Avatar
Member Avatar
+0 forum 9

Hi, Here is the File content. I want to use strtok to separate each. but the problem is if i use `strtok(string, "\",");`, the zip code (19428) of the detail is miss place and take State (PA) for the first record Because of "," in State. Although the second one is ok. Do u have any idea to fix it? I use `strtok(string, "'\",\"'\"");` for " `","` " and " `"` " but it is also not working. FirstName,LastName,Company,Address,City,County,State,ZIP,Phone,Fax,Email,Web "Brandon","Ortolano","Steele, Kendall D Esq","100 Front St", "Conshohocken", "Montgomery", "PA","19428", "610-834-2651", "610-834-9404","brandon@ortolano.com","http://www.brandonortolano.com" "Jonathon","Todeschi","Central Motive Power Inc","210 W Pennsylvania Ave #-650", "Towson", "Baltimore", …

Member Avatar
Member Avatar
+0 forum 13

Hi! I'm new to C and I'm having some problems in my program. It opens a .txt file then copies this to another .txt file but replaces a certain word with another word. It uses command line arguments. Example: //inside text.txt love is patient love is kind ... ./change love MONEY text.txt text_new.txt Output: //generates a .txt file <text_new.txt>. inside is MONEY is patient MONEY is kind ... I'm having problems replacing the words. We're asked to use strtok(). Here is my code [CODE] #include<stdio.h> #include<string.h> int main(int argc, char *argv[]) { FILE *oldfile; FILE *newfile; unsigned int i=0; char …

Member Avatar
Member Avatar
+0 forum 1

Hey everyone, I am working on a function that reads a text file (portion below) of data points arranged in two columns and stores the numbers only in an array of signal[2500][2]. The problem is, I need to do some search and replace on [I]some[/I] of the data points. Some are mV and msec, while others are uV and usec. As there are negative signs on some values, I cannot simply choose the first six places in each line (or similar). My intent is to convert those lines that are mV and ms to uV and usec and then store …

Member Avatar
Member Avatar
+0 forum 4

So, I'm doing a test of strtok and my csv reader to fill an array of structs. Each line in the csv has a bunch of country information, and I'm only pulling the 2nd, 3rd, 8th, and 9th fields in each line to make the structs. My biggest problem at the moment is an error stating: "expected specifier-qualifier-list before string" from within my struct. What's wrong with my struct declaration? I'm pretty sure this code works, as I've tested it on a small file without the structs, but let me know if I've mucked it up. [CODE]#include <stdio.h> #include <stdlib.h> …

Member Avatar
Member Avatar
+0 forum 2

please disregard this as i have figured out what was going on. i will delete this as soon as i know how.

Member Avatar
+0 forum 0

I am working on a Priority Based Scheduler which reads the process in from a file. I have it reading from file and printing to the screen. I'm trying to use strtok to tokenize a line from the process test file and store it in three different arrays. The layout of the process file is: Process Quanta Priority Process0 12 1 Process1 10 9 Process2 15 4 And so on for about 800 lines. I want it to token the spaces between the process and it's quanta and priority and store it in corresponding arrays. So basicly: Process0 will be …

Member Avatar
Member Avatar
+0 forum 6

Hello All i am trying to compile a simple code for the strtok but getting the error as segmentation fault ( core dumped ) .. any help would be appreciated. [CODE] #include <stdio.h> #include <netinet/in.h> #include <stdlib.h> #include <string.h> main() { char *test="asim.nazeer.helo.me"; char *rsl=strtok(test,"."); //while(1) //{ printf("%s",rsl); //} } [/CODE]

Member Avatar
Member Avatar
+0 forum 7

Hello everyone. I have a problem using strtok in C. I get a user input from the command line and I want to tokenize it with pipe ("|") as the delimeter and put the result in a double pointer variable. Here's my code: [CODE]char** argv; char *token; token = strtok(userInput, "|"); while(token != NULL){ *(argv++) = token; token = strtok(NULL, "|"); } *argv = '\0'; [/CODE] I then use this code to verify if it's well tokenized [CODE] while(*argv!= NULL) { if((strcmp(*argv, "|") == 0){ count = count + 1; } argv++; } printf("%d pipes", count); [/CODE] But it doesn't …

Member Avatar
Member Avatar
+0 forum 11

Hi, I need help with this, I'm reading a txt file that has this format: 10,4,12,6,18,24,7,8,15,14,25,2 So far, I read the file using fopen ().Also, I used strtok () to split the string into tokens, but i don't know how store the tokens into an array. any ideas? thanks [CODE] #include <stdio.h> #include <string.h> int main() { FILE * pFile; char mystring [100]; char * datos; pFile = fopen ("intermemory.txt" , "r"); if ( fgets (mystring , 100 , pFile) != NULL ) { puts (mystring); fclose (pFile); } //printf ("\nSplitting string \"%s\" into tokens:\n",mystring); datos = strtok (mystring,","); while …

Member Avatar
Member Avatar
+0 forum 2

Hi I am trying to make my homework about a command line calculator, and i am trying to divide the entered string into small parts and i am trying to use strtok for this. [CODE] #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> struct var { char name[10]; double value; }; void main() { char in[100], *temp[10],type; int i,j,k,temp1,temp2,temp3; k=0; printf("Enter the expression >>"); gets(in); temp[0]=strtok(in," "); for (i=1;temp[i]!=NULL;i++) { temp[i]=strtok(NULL," "); } for(k=0;k<10;k++) { printf("%s",temp[k]); } } [/CODE] But when i try to execute, it gives me the error "Run-Time Check Failure #2 - Stack around the variable 'temp' …

Member Avatar
Member Avatar
+0 forum 2

hi, this is something i keep running into. for example, in the following example of strtok, i'm splitting a given string on a space(" ") delimiter: [code] #include<stdio.h> #include<string.h> int main() { char str[]="1234563 34 7898"; char delim[]=" "; char* result=NULL; char new[15][3]; int i=0; int j=0; bzero(new, sizeof new); result=strtok(str,delim); i=0; while( result != NULL ) { printf( "result is \"%s\"\n", result ); strcpy(new[i],result); i++; printf("new[%d]=%s\n",i,new[i]); result = strtok( NULL, delim ); } return 0; } [/code] while result prints the output correctly, the contents of new[] are printed truncated. happens a lot of times and is probably a …

Member Avatar
Member Avatar
+0 forum 3

Hi... i have a little problem on my code... HI open a txt that have this: LEI;7671;Maria Albertina da silva;xxxx@gmail.com; 9;8;12;9;12;11;6;15;7;11; LTCGM;6567;Artur Pereira Ribeiro;fdsdfsd@gmail.com; 6;13;14;12;11;16;14; LEI;7701;Ana Maria Carvalho;asasssas@gmail.com; 8;13;11;7;14;12;11;16;14; -------------------------------------------------------------------------------- LEI, LTCGM are the college; 7671, 6567, 7701 is student number; Maria, Artur e Ana are the students name; [email]xxxx@gmail.com[/email], ...@gmail are emails from students; the first number of every line is the total of classes that students have; after that is students school notes; example: College: LEI Number: 7671 Name: Maria Albertina da Silva email: [email]xxxx@gmail.com[/email] total of classes: 9 Classe Notes: 8 12 9 12 11 6 15 …

Member Avatar
Member Avatar
+0 forum 2

Hello. I'm just starting out in C++ and am trying to figure out how to split a users string input into individual words and then put each word into a slot in an array. I think it's going rather well, but I'm running into some problems, and it would be great if you could help! Please try not to make it TOO complicated, I'm still learning. =) [CODE] #include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<fstream> #include<cstdlib> using namespace std; int main () { ifstream DataBank; DataBank.open("DataBank.txt",ios_base::app); if(!DataBank.is_open()){ cout << "Sorry, the program is experiencing problems with the DataBank." << endl; }else{ cout …

Member Avatar
Member Avatar
+0 forum 4

how would this be done [CODE]int main(void) { char string[]="231 number 73 word 1 2"; char *ele; ele=strtok(string," "); while (ele != NULL) { if (*ele == '0' || *ele == '1' || *ele == '2' || *ele == '3' || *ele == '4' || *ele == '5' || *ele == '6' || *ele == '7' || *ele == '8' || *ele == '9') TTS(ele); else printf("%s\n", ele); ele=strtok(NULL," "); } return 0; }[/CODE] I'm trying to separate the words from the numbers. So when tokenizing it encounters a number I can pass it to an array. the TTS function …

Member Avatar
Member Avatar
+0 forum 2

So I'm using Mysql to make a text-to-speech engine. Basically any given phrase by the database is returned to my script, which has to say every word and number, if any, by way of voice . For the voices I'm using Asterisk, but that's another problem of my own lol The problem I'm having is this: the sql results are given in way of arrays, like this: char test[10][20] so test[0] is the first line of query, test[1] second and so on. So I just use the strtok function on the array using " " (space) as the tokenizer and …

Member Avatar
Member Avatar
+0 forum 4

I have got an example for cplusplus.com for converting a string into a char array so i can split in into tokens and adds to a vector and it works fine in the main method but if i try and create a separate function and pass a string as a parameter, the program crashes with no explanation. It compiles fine. Have i created the function type correctly? I want to create a vector of strings so i can output each vector. [CODE]// strings and c-strings #include <iostream> #include <cstring> #include <string> #include <vector> using namespace std; vector<string> SplitString (string aString) …

Member Avatar
Member Avatar
+0 forum 1

The End.