C/C++ :: Can Use Strtok For Splitting A String With A Certain Pattern
Oct 31, 2012
I have a string like "THIS::IS::THE:EXAMPLE::STRING"
I want to split the string to tokens based on "::".
The tokens should be:
THIS
IS
THE:EXAMPLE
EXAMPLE
STRING
View 1 Replies
ADVERTISEMENT
Jul 14, 2014
I am trying to make simpler equivalent of strtok().i want to separate string for my command line program. here is what i came up with
Code:
PVOID CmdArgs(PWCHAR Arg){
PWCHAR Return[10];
int I=0,s=0;
}
[code]....
i can not use winapi or standard c library because project im doing is pure ntdll api program (subsystem native in other words)
View 4 Replies
View Related
Jun 7, 2014
I have been programming a lot in Java lately which made me forget a few things in C++. So I tried doing a few simple things. I am having a hard time splitting up a mega string of 6000 names. However I did break them apart as far as their appearance in the console. But I tested it by placing it into a vector and it is still a mega string.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
class CalulateNames
[Code] ....
} I have tried using the following as well with no luck
Code:
str.replace();
str.erase();
I am hoping to finding something like in Java or the ability to handle it this way.
Code: line.split(",");
View 13 Replies
View Related
Jan 15, 2013
The following code shows bad memory access error (segmentation fault) when I run it. It does this right after it asks for name and the user has entered it.
#include <iostream>
#include <sstream>
using namespace std;
struct Name {
string first;
string last;
[Code] ....
View 4 Replies
View Related
Feb 18, 2014
i have an array of strings that i need to split into 2 different string.
Code:
string title = " "Rebecca" "Alfred Hitchcock" ";
so far all the data is in one string called title
//need to break them into 2 strings, title and director
// title should contain = Rebecca
// director should contain alfred hitchcock
which string fuctions can i use to split these 2 and remove the quotes???
View 6 Replies
View Related
Sep 26, 2013
I'm having trouble with this code. What I'm trying to do is to read a line from a file and cut that line into two pieces, one is the keyword and the other is the definition. I want to read up to when there is a dash and assign that line to key and then assign the rest of the line to def. After that I copy key to the struct DictEntries.key and def to DictEntries.def. The output of this shows only the definition for both DictEntries.key and DictEntries.def but if I use "puts(key);" I see the keyword.
Code:
while(!feof(dictionary))
{
char line[200];
char *key,*def;
fgets(line,sizeof(line),dictionary);
key = strtok(line,"-");
}
[code]....
View 12 Replies
View Related
Jun 4, 2014
With respect to below string, i need to split it and store the values accordingly as below,
P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13
pri_dev_type=1-0050F204-1 name='p2p-TEST1' config_methods=0x188 dev_capab=0x27 group_capab=0x0 wfd_dev_info=000006015d022a0032
dev_addr = fa:7b:7a:42:02:13
dev_type = 1-0050F204-1
dev_name = p2p-TEST1
config_method = 0x188
dev_capab = 0x27
group_capab = 0x0
dev_info = 000006015d022a0032
How to split it as above and store. I am new to c++
View 2 Replies
View Related
Sep 23, 2014
I have the following string array
string[] output= input.toArray();
each index has a set of two characters, for example:
output[0] has 'th', output[1] has 'is'
I want to take t and h and compare them or do anything with them, but it must be in pairs.
I tried foreach but I don't know if there is a way to compare the element with the next element .
View 2 Replies
View Related
Feb 18, 2014
I have been looking everywhere, but the only place I have seen it done is Objective C. The Question: how do I split a string, input by the user, into an array of characters? No code shown because I know no commands that do this.
--Input by user as in fgets, or scanf().
View 2 Replies
View Related
Sep 26, 2013
How to write a printPattern() function?
The function takes in a parameter i.e. a char pointer. It handles the parameter as a Cstyle string i.e. a NULL terminated char array. It does not make use of the stringclass or its associated functions. In other words, the function examines every char element in the array until it encounters the terminating NULL character.
Starting from this int main :
int main() {
char string1[] = "Application of C++";
printPattern(string1);
}
[Code].....
View 1 Replies
View Related
Nov 28, 2013
Assuming that we have the string :
Code:
***HELLO&SIR. & and * is the delimiters.
My question is how strtok will work in the beginning?
According to this to determine the beginning and the end of a token, the function first scans from the starting location for the first character not contained in delimiters (which becomes the beginning of the token). And then scans starting from this beginning of the token for the first character contained in delimiters, which becomes the end of the token. The scan also stops if the terminating null character is found.
This end of the token is automatically replaced by a null-character, and the beginning of the token is returned by the function. strtok will replace the first * with '' and the next call will start from the second * puts '' there and again the same with the third * ?
View 8 Replies
View Related
Sep 27, 2014
How to use strtok and strcpy in a file?
View 1 Replies
View Related
Nov 20, 2013
I wrote this program, it's supposed to take a user-specified file, which has a bunch of numbers, and add all the numbers in a line and give me a sum and average.
Sample file:
------------------------------------
2 1 2
3 1 2 3
4 1 2 3 4
------------------------------------
This would output:
------------------------------------
Group Size = 2
i = 1 number = 1 Sum = 1
i = 2 number = 2 Sum = 3
Average = 1.50
Group Size = 3
i = 1 number = 1 Sum = 1
i = 2 number = 2 Sum = 3
i = 3 number = 3 Sum = 6
Average = 2.00
Group Size = 4
i = 1 number = 1 Sum = 1
i = 2 number = 2 Sum = 3
i = 3 number = 3 Sum = 6
i = 4 number = 4 Sum = 10
Average = 2.50------------------------------------
// END CONTEXT
Anyway, I wrote this program. Here it is. But strtok doesn't want to advance to teh next token?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
int a, sum, number, groupsize;
}
[code].....
View 4 Replies
View Related
Jul 23, 2013
I am beginner in C++ programming. And i was try use STRTOK code with NULL fields, but in ARRAY fields NULL values is skiped. For example:
input text in Memo2:
AnsiString PAT02[100][20];
for (int IndexVRadku02 = 0; IndexVRadku02 < Memo2->Lines->Count ; IndexVRadku02++) {
AnsiString PNF02 = Memo2->Lines->Strings[IndexVRadku02];
char * PN02;
[Code] ....
Result:
Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6
But i need this result:
Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6
View 2 Replies
View Related
Mar 1, 2015
I'm playing around with parts of code and am coming across some errors. Most of my concern is related to strtok(). I've used it before but with a char* named token. I used a while loop to continuously check whether token was equal to NULL. In the following code, however, there aren't any checks. I was wondering if that is why this code prints (null) while running. Also, I would like to know if it is possible to read input like this code attempts to do - assigning tokens to each variable one after the other.
The format of the input:
Zucchini, Squash, pound
Yellow, Squash, pound
Tomatoes, Ugly Ripe, each
#include <stdio.h>
#include <stdlib.h>
[code]....
View 3 Replies
View Related
Sep 18, 2013
I am having a problem with the output of a file. My function does everything it needs to do with the exception of one line. I have a .dat file with the following:
Code:
joe clint james brint howard
jimmy
alexander
*
me
When I run the function my output is as such:
Code:
file opened
word: joe
digit: 3
word: clint
digit: 5
word: james
[Code] .....
ERROR non alphanumeric digit on line 4!
File closed "Howard" is only six digits in length. Also it seems to skips a line in the output which could be the extra character but I am not sure. What I find very interesting is the other names, (jimmy & alexander) on separate lines do not have that problem.
Here is my function:
Code:
#include "main.h"
#include "fileCheck.h"
int fileCheck(FILE *fp){
int line_count = 0;
int ret_val = 0;
int digit_count = 0;
char file[BUFF];
[Code] .....
How I can correct this? I am aware of sscanf to parse the line but I do not know the format of the file. All I know is the file will be alphanumeric and if there is a non-alphanumeric, I must print out an error with the line it occurred on such as the above output.
View 3 Replies
View Related
Feb 28, 2014
I had an assignment to do a palindrome program but im stuck in this part.
"This c-string will be sent to a function that will remove all spaces and punctuation marks from its c-string as well as change any uppercase letters to lowercase. Use string tokens to eliminate the spaces & punctuation marks. Make sure you include the NULL as you concatenate the tokens into a c-string. Then copy back into the original c-string for the pass by reference."
void tokenptr(char drome[]) {
char *token;
size_t i;
token = strtok(drome, " ,.!:;?");
while (token != '