fscanf to read string between " mark

M

Matrixinline

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
 
J

Jens Thoms Toerring

Matrixinline said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top