Sponsored Content
Top Forums Programming C++ getline, parse and take first tokens by condition Post 302917960 by yifangt on Friday 19th of September 2014 01:47:30 PM
Old 09-19-2014
Two questions related the movement of the pointer char *tok and for my planned string map of sequences.
With multiple strings as:
Code:
buf1[128]= "This is a test";
buf2[128]= " Second string with a leading space"
buf3[128]= "";
buf4[128] ="\n\t\nForth string with leading unprintable chars"

Using your my_strtok() function, it is easy to parse each string(char array) and print out on screen as the pointer moves forward.
Question 1: How to save (NOT print) concatenated strings in memory?
Code:
string1="Thisisatest"; 
string2="Secondstringwithaleadingspace"
string4="Forthstringwithleadingunprintablechars"

Of course string3 will be an empty one, and a master string
Code:
string ="ThisisatestSecondstringwithaleadingspaceForthstringwithleadingunprintablechars"

The reason I ask for "save" is for the manipulation of the variable char *tok.
I seem to be quite vague about this pointer in the stack or/and heap(if I am not too wrong with the two terms!?)
Question 2: How is the pointer char *tok (and probably some new pointers to save the concatenated strings) moving back and forth to have those individual concatenated strings and the master string?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

tokens in unix ?

im trying to remove all occurences of " OF xyz " in a file where xyz could be any word assuming xyz is the last word on the line but I won't always be. at the moment I have sed 's/OF.*//' but I want a nicer solution which could be in pseudo code sed 's/OF.* (next token)//' Is... (6 Replies)
Discussion started by: seaten
6 Replies

2. UNIX for Advanced & Expert Users

How to parse through a file and based on condition form another output file

I have one file say CM.txt which contains values like below.Its just a flat file 1000,A,X 1001,B,Y 1002,B,Z ... .. total around 4 million lines of entries will be in that file. Now i need to write another file CM1.txt which should have 1000,1 1001,2 1002,3 .... ... .. Here i... (6 Replies)
Discussion started by: sivasu.india
6 Replies

3. Shell Programming and Scripting

: + : more tokens expected

Hello- Trying to add two numbers in a ksh shell scripts and i get this error every time I execute stat1_ex.ksh: + : more tokens expected stat1=`cat .stat1a.tmp | cut -f2 -d" "` stat2=`cat .stat2a.tmp | cut -f2 -d" "` j=$(($stat1 + $stat2)) # < Here a the like the errors out echo $j... (3 Replies)
Discussion started by: Nomaad
3 Replies

4. Shell Programming and Scripting

Shell script to parse/split input string and display the tokens

Hi, How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant. The input file could be as below: ... (3 Replies)
Discussion started by: yajaykumar
3 Replies

5. Shell Programming and Scripting

Replacing tokens

Hi all, I have a variable with value DateFileFormat=NAME.CODE.CON.01.#.S001.V1.D$.hent.txt I want this variable to get replaced with : var2 is a variable with string value DateFileFormat=NAME\\.CODE\\.CON\\.01\\.var2\\.S001\\.V1\\.D+\\.hent\\.txt\\.xml$ Please Help (3 Replies)
Discussion started by: abhinav192
3 Replies

6. Shell Programming and Scripting

+: more tokens expected

Hey everyone, i needed some help with this one. We move into a new file system (which should be the same as the previous one, other than the name directory has changed) and the script worked fine in the old file system and not the new. I'm trying to add the results from one with another but i'm... (4 Replies)
Discussion started by: senormarquez
4 Replies

7. Shell Programming and Scripting

Need tokens in shell script

Hi All, Im writing a shell script in which I want to get the folder names in one folder to be used in for loop. I have used: packsName=$(cd ~/packs/Acquisitions; ls -l| awk '{print $9}') echo $packsName o/p: opt temp user1 user2 ie. Im getting the output as a string. But I want... (3 Replies)
Discussion started by: AB10
3 Replies

8. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

9. Programming

Reading tokens

I have a String class with a function that reads tokens using a delimiter. For example String sss = "6:8:12:16"; nfb = sss.nfields_b (':'); String tkb1 = sss.get_token_b (':'); String tkb2 = sss.get_token_b (':'); String tkb3 = sss.get_token_b (':'); String tkb4 =... (1 Reply)
Discussion started by: kristinu
1 Replies

10. Shell Programming and Scripting

Parse xml in shell script and extract records with specific condition

Hi I have xml file with multiple records and would like to extract records from xml with specific condition if specific tag is present extract entire row otherwise skip . <logentry revision="21510"> <author>mantest</author> <date>2015-02-27</date> <QC_ID>334566</QC_ID>... (12 Replies)
Discussion started by: madankumar.t@hp
12 Replies
WCSTOK(3)						   BSD Library Functions Manual 						 WCSTOK(3)

NAME
wcstok -- split wide-character string into tokens LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <wchar.h> wchar_t * wcstok(wchar_t *restrict ws1, const wchar_t *restrict ws2, wchar_t **restrict ptr); DESCRIPTION
The wcstok() function is used to isolate sequential tokens in a null-terminated wide character string, ws1. These tokens are separated in the string by at least one of the characters in ws2. The first time that wcstok() is called, ws1 should be specified; subsequent calls, wishing to obtain further tokens from the same string, should pass a null pointer instead. The separator string, ws2, must be supplied each time, and may change between calls. The context pointer, ptr, must be provided on each call. The wcstok() function is the wide character counterpart of the strtok_r() function. RETURN VALUES
The wcstok() function returns a pointer to the beginning of each subsequent token in the string, after replacing the token itself with a null wide character (L''). When no more tokens remain, a null pointer is returned. EXAMPLES
The following code fragment splits a wide character string on ASCII space, tab, and newline characters, writing the resulting tokens to stan- dard output: const wchar_t *seps = L" "; wchar_t *last, *tok, text[] = L" one two three "; for (tok = wcstok(text, seps, &last); tok != NULL; tok = wcstok(NULL, seps, &last)) wprintf(L"%ls ", tok); COMPATIBILITY
Some early implementations of wcstok() omit the context pointer argument, ptr, and maintain state across calls in a static variable like strtok() does. SEE ALSO
strtok(3), wcschr(3), wcscspn(3), wcspbrk(3), wcsrchr(3), wcsspn(3) STANDARDS
The wcstok() function conforms to ISO/IEC 9899:1999 (``ISO C99''). BSD
October 3, 2002 BSD
All times are GMT -4. The time now is 09:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy