Hi
I am writing a Program
in which i get input as
#C1012,S,A#C101 3,S,U
I want to get C1012,S,A using strtok and then pass this to function
CreateCopies
which will further strtok this (C1012,S,A) and store the required
values.
Now here is the piece of that code:
#define DELIM2 #
char * field;
char fieldcopy[20];
/*Here i have input as #C1012,S,A#C101 3,S,U*/
field = strtok(NULL,DEL IM2);
while(field != NULL)
{
strcpy(fieldcop y,field);
CreateCopies(co py,fieldcopy,No Copies);
field = strtok(NULL,DEL IM2);
printf("Field in CreateVideo is %s\n",field);
}
1.Now if I call CreateCopies the strtok doesn't tokenize till the end.
I get to call CreateCopies
only once.
2.But if i comment the CreateCopies call, it does tokenize till the end
and prints the rrquired vales.
In the first case the second time i call strtok 'field' gets a value of
NULL instead it should get the second token.
Why this behaviour??? 2 2092
On Tuesday 14 March 2006 09:18, ma***********@g mail.com opined (in
<11************ **********@p10g 2000cwp.googleg roups.com>): Hi I am writing a Program in which i get input as
#C1012,S,A#C101 3,S,U
I want to get C1012,S,A using strtok and then pass this to function CreateCopies which will further strtok this (C1012,S,A) and store the required values.
Now here is the piece of that code:
#define DELIM2 # char * field; char fieldcopy[20];
/*Here i have input as #C1012,S,A#C101 3,S,U*/ field = strtok(NULL,DEL IM2); while(field != NULL) { strcpy(fieldcop y,field); CreateCopies(co py,fieldcopy,No Copies); field = strtok(NULL,DEL IM2); printf("Field in CreateVideo is %s\n",field); }
1.Now if I call CreateCopies the strtok doesn't tokenize till the end. I get to call CreateCopies only once. 2.But if i comment the CreateCopies call, it does tokenize till the end and prints the rrquired vales. In the first case the second time i call strtok 'field' gets a value of NULL instead it should get the second token.
Why this behaviour???
You don't show or tell what `CreateCopies` does, but I'll bet you it
uses `strtok` as well. If it does, therein lies your problem. You're
"resetting" `strtok`. You have to finish tokenising the original string
with `strtok(NULL,.. .)` calls before calling `strtok` again with the
new string to parse.
--
BR, Vladimir
The average, healthy, well-adjusted adult gets up at seven-thirty in
the morning feeling just terrible.
-- Jean Kerr
>You don't show or tell what `CreateCopies` does, but I'll bet you it uses `strtok` as well. If it does, therein lies your problem. You're "resetting" `strtok`. You have to finish tokenising the original string with `strtok(NULL,.. .)` calls before calling `strtok` again with the new string to parse.
Thanx that did solved my Problem.
I forgot to comment one strtok in CreateCopies.
Thanks again. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ramprasad A Padmanabhan |
last post by:
Hello all
I want to read into a string an input from QUERY_STRING how do I
ensure that scanf reads more chars into the string that it can hold
eg
{
char* s1;
char* data;
long n;
|
by: daniel |
last post by:
Hi everyone,
I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.
Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);
|
by: ern |
last post by:
I'm using strtok( ) to capture lines of input. After I call
"splitCommand", I call strtok( ) again to get the next line. Strtok( )
returns NULL (but there is more in the file...). That didn't happen
before 'splitCommands' entered the picture. The problem is in
splitCommands( ) somehow modifying the pointer, but I HAVE to call that
function. Is there a way to make a copy of it or something ?
/* HERE IS MY CODE */
char *...
|
by: manochavishal |
last post by:
Hi
I am writing a Program
in which i get input as
#C1012,S,A#C1013,S,U
I want to get C1012,S,A using strtok and then pass this to function
CreateVideo
which will further strtok this (C1012,S,A) and store the required
values.
|
by: hu |
last post by:
hi, everybody!
I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0.
Program is simple, but mistake is confusing. First, the below code can get
right outcome:"ello world, hello dreams."
#include <stdafx.h>
#include <string.h>
#include <stdio.h>
int main()
| |
by: machikelxol |
last post by:
I'm having a strange error when I try reading from a file. here is the
code:
buffstring values = 1, 2, 3, 4 and then it crashes afterwards on the
4th iteration.
This works fine until the fourth iteration.
breaks on this line: buffString = new char;
The contents of the text file it is reading:
1,1,1,1,1,1,1,1,1,5,6,7,8,9
2,2,2,2,2,2,2,2,2
3,3,3,3,3,3,3,3,3
|
by: anant |
last post by:
Hi all
The below code is reading string and then tokenizin it and reading all
the info. But i want to call a csv file and it should then read a
string from dt file. So what midification should i do in the below
code. Its main code, all the functions are defined well. So just wanna
know how to include some extra code to open the file and read each
line.
Thanks a lot
typedef struct
{
|
by: shrik |
last post by:
I have following error :
Total giant files in replay configuration file are :
File name : /new_file/prob1.rec
Given file /new_file/prob1.rec is successfully verified.
Splitting for giant file /new_file/prob1.rec started. Please wait....
In while loop of request searching
*** glibc detected *** ./a.out: free(): invalid next size (normal): 0x099da890 ***
======= Backtrace: =========
/lib/libc.so.6
|
by: magicman |
last post by:
can anyone point me out to its implementation in C before I roll my
own.
thx
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |