By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

fscanf to read string between " mark

P: n/a

Hi All,

File Text.txt
Contains following text as :
"C:\program file\application data\details\app" "D:\Program File"
I tried to read that data as
fscanf(oFp, "%s %s", sCopyDirectory, sToDirectory);

it gives me
sCopyDirectory = "C:\program
sToDirectory= file\application

How can I read a full string between a two double quote mark from a
file?

Well we can read "C:\program file\application data\details\app" "D:
\Program File"
in two character pointers easily. I need the same solution but reading
from a file.

Thanks
Anup
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Matrixinline <an**********@gmail.comwrote:
Hi All,
File Text.txt
Contains following text as :
"C:\program file\application data\details\app" "D:\Program File"
I tried to read that data as
fscanf(oFp, "%s %s", sCopyDirectory, sToDirectory);
it gives me
sCopyDirectory = "C:\program
sToDirectory= file\application
How can I read a full string between a two double quote mark from a
file?
Try

fscanf( fp, "\"%[^\"]\" \"%[^\"]\"", sCopyDirectory, sToDirectory );

The '%[^\"]' tells fscanf() to read everything up (but not
including) the next double quote. You may want to add the
maximum number of characters that fit into the target string
between the '%' and the '[', otherwise you may try to write
more characters to the target string than fits in there (and
don't forget about the trailing '\0' character that also needs
to fit in there;-)
Well we can read "C:\program file\application data\details\app" "D:
\Program File"
in two character pointers easily. I need the same solution but reading
from a file.
What means "Well we can read"? Reading from standard input and
a file doens't make any noticable difference here. And be care-
ful with your terminology, you can't "read into a character
pointer", you can only write to where a character pointer points
to, and that, of course, only if it points to enough memory
you own.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.