Solved

scanf question

Posted on 2004-08-03
2
312 Views
Last Modified: 2010-07-27
I've never really used scanf or fscanf before, and I was wondering if it would work for this situation:

I have a file in the format of:

var1=something
var2=somethingelse...

I tried using:
fscanf(f,"%s=%s\r\n",szVar,szVal);

That didn't work since szVar got filled with the entire line.  Can scanf do this, or do I need to do the parsing myself?
0
Comment
Question by:lwinkenb
2 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
Comment Utility
Hi lwinkenb,

> fscanf(f,"%s=%s\r\n",szVar,szVal);

fscanf (f, "%[^=]=%s",szVar,szVal);

make sure that memory referenced by szVar and SzVal is writable

Sunnycoder
0
 
LVL 5

Author Comment

by:lwinkenb
Comment Utility
Thanks sunny :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now