473,804 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parsing string into an array

I would like to parse a string into an array. I found on the net
the following codes which parse a string and print it. The result
is exactly what I want:

char * pch;
pch = strtok (buffer," ");
while (pch != NULL)
{
printf ("%s\n",pch) ;
pch = strtok (NULL, " ,.");
}

To store the output to a string array, I created a two-dimensional
array and copied the output to the array:

char output[5][55];
char * pch;
int i=0;
pch = strtok (str," ");
while (pch != NULL)
{
strcpy(output[i],pch);
printf ("%s\n",pch) ;
printf("output[%d] is %s.\n";i,output[i++]);
pch = strtok (NULL, " ,.");
}

This doesn't work. What's in the output array is nothing like the
output (on screen). How should it be done?
Nov 14 '05
15 3633
CBFalconer wrote:
Joe Wright wrote:

... snip ...
(Do us a favor. See if you can turn off the annoying MIME stuff)


... snip ...

I am among the first to bitch and moan about mime and html in
Usenet, but I see none in this thread. Has something stripped it
on the path from there to here?


I suspect you have turned it off in your reader, as I now have.
--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #11
In article <42************ ***@yahoo.com>,
CBFalconer <cb********@wor ldnet.att.net> wrote:
I am among the first to bitch and moan about mime and html in
Usenet, but I see none in this thread. Has something stripped it
on the path from there to here?


It isn't the typical obvious MIME so my reader (trn) didn't notice
it either. He did, though, have a Content-type: text/plain
header that specified a charset of Big5. Content-Type is a MIME
header, and on some systems the Big5 (i.e., one of the Chinese
encodings) would trigger different behaviour than if it were
(say) 8859-1 .
--
Studies show that the average reader ignores 106% of all statistics
they see in .signatures.
Nov 14 '05 #12
Guillaume <"grsNOSPAM at NOTTHATmail dot com"> writes:
John Smith wrote:
To store the output to a string array, I created a two-dimensional
array and copied the output to the array:

char output[5][55];
(snip)
This doesn't work. What's in the output array is nothing like the
output (on screen). How should it be done?
[snip] As a side note, I will add that outside of textbooks, multidimensiona l
arrays in C are not particularly useful. Their syntax is often
misleading (in my opinion) and they can serve only very limited
purpose. I tend to prefer arrays of arrays, which are easier to handle
and more flexible (in my opinion).


I'm not certain what distinction you're making here. The declaration
char output[5][55];
defines output as an array of arrays of char, which is the closest
thing C has to a multi-dimensional array.

Perhaps you're thinking of an array of pointers to arrays?

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #13
John Smith <js****@company .com> spoke thus:
(Is MIME turned off this time? Hope it is.)


It seems not to be - the header that Walter referred to is still
present:

Content-Type: text/plain; charset=Big5

although it also looks like the people it annoys have been able to
change their newsreader configuration, so you may not have to worry
about it (tin has not complained about it here, FWIW).

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #14
Christopher Benson-Manica wrote:
John Smith <js****@company .com> spoke thus:
(Is MIME turned off this time? Hope it is.)


It seems not to be - the header that Walter referred to is still
present:

Content-Type: text/plain; charset=Big5

although it also looks like the people it annoys have been able to
change their newsreader configuration, so you may not have to worry
about it (tin has not complained about it here, FWIW).


There is no attached mime section, nor any html. So I see no harm
in it, although I am one of the most vocal html/mime haters
extant.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #15

Christopher Benson-Manica wrote:
John Smith <js****@company .com> spoke thus:
(Is MIME turned off this time? Hope it is.)


It seems not to be - the header that Walter referred to is still
present:

Content-Type: text/plain; charset=Big5

although it also looks like the people it annoys have been able to
change their newsreader configuration, so you may not have to worry
about it (tin has not complained about it here, FWIW).

All it does for me is change the font from the default to a sans-serif
one. It's annoying to a certain extent, but not a killer. I haven't
figured out how to make XanaNews ignore it, if even possible.

Brian

Nov 14 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2660
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. <txtNameUSState>CALIFORNIA</txtNameUSState>
0
6473
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6, 'b_id' => 9, 'c_id' => 3,
6
2122
by: Ulrich Vollenbruch | last post by:
Hi all! since I'am used to work with matlab for a long time and now have to work with c/c++, I have again some problems with the usage of strings, pointers and arrays. So please excuse my basic question: I want to parse a string like "3.12" to get two integers 3 and 12. I wanted to use the function STRTOK() I wrote a main- and a subfunction like: main() {
1
13302
by: Andre Ranieri | last post by:
I'm having trouble programatically inserting an Excel file into an Image column in our CRM package's SQL 2000 database. The function appears to work ok, but when I attempt to access the file through the application's front end the file appears to be corrupt. The front-end application has a way of inserting files to the column, however when I analyze this in SQL Profiler the contents of the Byte array appear to be quite different than the one...
12
2562
by: Klaus Alexander Seistrup | last post by:
Hi group, I am new to xgawk (and seemingly to xml also), and I've been struggling all afternoon to have xgawk¹ parsing an XHTML file containing a hCard², without luck. I wonder if you guys could give me a push... Let's say I have the following XHTML file: #v+
9
1992
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a good time in this process to create a new instance of my Message object. While messing around with...
2
4889
by: RG | last post by:
I am having trouble parsing the data I need from a Serial Port Buffer. I am sending info to a microcontroller that is being echoed back that I need to remove before I start the actual important data reading. For instance this is my buffer string: 012301234FFFFFFxFFFFFFxFFFFFFx Where the FFFFFF is my Hex data I need to read. I am using the "x" as a separater as I was having problems using the VbCrLf. But I think
1
2207
nine72
by: nine72 | last post by:
Ok, I am at a complete loss on this and have finally come to the XML Parsing Gods (and perhaps a PHP minor deity) for guidance… I will try my best to describe what I have going on… 1) I have 15 form pages, well over 500 potential fields, which are written in PHP. While most pages are one time entry forms, there are 5 that can be “recycled” as many times as needed. An example would be the Contacts Form. A user can give me 1 contact and move...
9
6284
nine72
by: nine72 | last post by:
Ok, so I have figured out how to parse an custom returned XML doc (actually a string that I made into a doc for testing). At this point I am attempting to integrate my parse routine into my main code and I am having an issue getting it to mesh, and am looking for a little help in how to 1) combine the two and 2) how to catch the incoming xml string. FYI the string is sent to me as a return message to an xml message that I send first....
0
9714
marktang
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...
0
9594
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,...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
isladogs
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...
0
6863
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();...
0
5531
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...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.