473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

char problem

Kay
I have obtained whole sentence by using this. If the sentence like this

Sentence 1: Harry Protter; M; 15
Sentence 2: Peter Parker; M; 23

char wholeLine[45];
//obtain the whole string
fgets(wholeLine, 45, ptr);

how can I break up this sentence without storing the semi-colon and save
it into three different character array?

some one told me that it can be done by this

char rest_name[40];
rest_name = strtok( wholeLine, ';');

But It can't do it, anyone can guide me ? Thx

Nov 14 '05 #1
2 954

"Kay" <er*********@yahoo.com.hk> wrote in message
news:41************@yahoo.com.hk...
I have obtained whole sentence by using this. If the sentence like this

Sentence 1: Harry Protter; M; 15
Sentence 2: Peter Parker; M; 23

char wholeLine[45];
//obtain the whole string
fgets(wholeLine, 45, ptr);

how can I break up this sentence without storing the semi-colon and save
it into three different character array?

some one told me that it can be done by this

char rest_name[40];
rest_name = strtok( wholeLine, ';');

But It can't do it, anyone can guide me ? Thx


Dude..
Your query was addressed just a couple of days before in the same group.

Subj: fscanf and linked list problem

Dont repost !!

- Ravi
Nov 14 '05 #2

"Kay" <er*********@yahoo.com.hk> wrote
I have obtained whole sentence by using this. If the sentence like this

Sentence 1: Harry Protter; M; 15
Sentence 2: Peter Parker; M; 23

char wholeLine[45];
//obtain the whole string
fgets(wholeLine, 45, ptr);

how can I break up this sentence without storing the semi-colon and save
it into three different character array?

some one told me that it can be done by this

char rest_name[40];
rest_name = strtok( wholeLine, ';');

But It can't do it, anyone can guide me ? Thx

Firstly, a buffer of 45 characters is rather mean. Unless there is a limit
imposed by your format, why not use 1024?

Secondly, strtok() returns a pointer to the portion of the string after the
separator, and replaces the separator with a NUL. It does not return an
array of characters.
It is quite a tricky function to use, so read your documentation carefully.
Nov 14 '05 #3

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

Similar topics

5
by: Alex Vinokur | last post by:
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message news:4180f756.197032434@news.individual.net... to news:comp.lang.c > ben19777@hotmail.com (Ben) wrote: > > 2) Structure casted into an...
6
by: Charlie | last post by:
Dear all, I am stuck on this problem, couldn't find an answer on any C++ book in the bookshop. Following is a cut of my program, and its error message:...
5
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file and copies the contents into the two char*s. Now...
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
24
by: kevin.hall | last post by:
Is char** (or char*) implicitly convertible to 'const char * const *'? I couldn't find anything about it in the standard. MSVS 8.0 allows this. I'm curious if I'll run into trouble with other...
8
by: eagle_jyjh | last post by:
For example: the msg = temp_buf; is alwawys ok? //test_msg.cpp struct msg_head { char a01;
5
by: Stephen Cawood | last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no results). I have a working wrapper DLL (I can get back simple things like int), but I'm having issues dealing with an array...
21
by: Wisdo | last post by:
Hi All, char to char ** is compile error. why? if i hava a string array. yes. it's not safe and it's better to use vector<stringinstead. but my point is the language feature. char...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.