LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2004, 07:36 AM   #1
pantera
Member
 
Registered: May 2004
Posts: 80

Rep: Reputation: 15
extraction of words


i have a character type arrray which contains the datas in following format
abcd:dhdh
i need to find the characters before the ":"
how can i do that
i am using c programming in linux
 
Old 10-15-2004, 07:52 AM   #2
bahramH
Member
 
Registered: Apr 2004
Location: France
Distribution: Mandrake
Posts: 67

Rep: Reputation: 15
many possibilities. Here is one which does not use any special function. Let's suppose your array is called "something".

i=0;
while(something[i] != ':' ) i++;

then "i" is your upper limit. You may add additional checks in case your string does not contain any ":"
 
Old 10-15-2004, 08:06 AM   #3
m00t00
Member
 
Registered: Sep 2004
Distribution: Slackware 10, Gentoo
Posts: 292

Rep: Reputation: 30
strtok(). Read the man page its good.
 
Old 10-15-2004, 02:02 PM   #4
rustynailz
Member
 
Registered: Jun 2004
Distribution: MDK 9.2/10.0, VectorLinux 4.0
Posts: 50

Rep: Reputation: 15
strchr() is a better option here, as you don't have to worry about memory allocation, etc like strtok().
 
Old 10-15-2004, 02:28 PM   #5
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Code:
char *string="wow:cool:sweet:baby"
char *pt, *pt2;
pt=string;

while(1)
{
	pt2=strchr(pt, ':');
	if (pt2) *pt2=0;

	printf("Parsed string: %s\n", pt);
	if (pt2)
		pt=pt2+1;
	else
		break;
}
Untested... but you get the idea.

You're welcome by the way.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
infomation extraction Dave Kelly Programming 2 10-27-2005 08:56 PM
Extraction error Fcm Linux - Software 1 02-09-2005 05:58 PM
Search and Replace: Asian Words to English Words ieeestd802 Linux - Software 0 10-27-2004 07:48 PM
BTarball Extraction harperonline Linux - General 2 02-05-2004 08:23 PM
Extraction failed efus Linux - Software 4 10-17-2003 04:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration