LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-05-2011, 06:03 PM   #1
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Parsing mountpoint from /etc/mtab (parsing "string") in C


Hi all,

Note that my knowledge about C is very limited so please forgive my ignorance.

I am reading /etc/mtab.
The goal is to have the mountpoints from those lines.
In most programming languages there are some methods like "split" and "section" in QString, ...
So the part I want is seperated by spaces.

I wonder if there is an easy way to accomplish this or if I should check out the position of the first space, then strcpy , check the first space in that new string, then do the strcpy or strdup again.
This seems rather complicated.

Thanks in advance for any advice/help!
 
Old 09-05-2011, 06:06 PM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
Actually this seems a rather good candidate:
http://pubs.opengroup.org/onlinepubs...ns/strtok.html
 
Old 09-05-2011, 06:15 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
If you're using Linux, /proc/mounts has more reliable information in a more machine-readable format. You can also use fscanf to avoid a lot of the mess involved with tokenizing since the file format is consistent. Here's another thread that deals with reading mount points in C (see post #8), although a lot more was required of that operation.
Kevin Barry
 
Old 09-06-2011, 05:33 PM   #4
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
In the end I decided to go for just sending the whole line to the client.
This gives the client the ability to have more data about the mountpoints. (for example if they are mounted through bind, are nfs mounts, ...)

Thanks for your advice and the link to the thread. I have read it and that will probably come in handy in the future
 
  


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
Xml parsing using "libxml2.so" library shankar.489 Linux - Newbie 3 03-09-2011 12:54 AM
Parsing String. msgforsunil Linux - Newbie 8 06-11-2009 01:47 PM
Programming in BASH - Parsing a String Mistro116@yahoo.com Programming 9 06-18-2008 06:43 PM
string parsing using perl bharatbsharma Programming 1 12-05-2007 06:04 AM
Porting to Fedora gcc 4.0 -parsing backward slash("\") comma(",") code_blew Programming 1 04-26-2006 04:07 PM

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

All times are GMT -5. The time now is 10:29 AM.

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