?
Solved

WriteProfileString trying to save an array to registry ...

Posted on 2000-04-24
9
Medium Priority
?
643 Views
Last Modified: 2008-03-10
Win32 Api, Visual C++

Array is nndata[48]


void CW1Dlg::SaveProfile()
{
      CWinApp* app = AfxGetApp();
      app->WriteProfileString("profile", "somedata", XXXXXX.GetXXX());
}

something like this. But i dont know how to get the array in there. I still cannot work with this MSDN library. I find nothing usefull in there.

Thanks for any help.
0
Comment
Question by:peter_b
  • 5
  • 4
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 2744542
What you mean by XXXXX.GetXXXX() is unclear.   The last parameter should be a pointer to a NUL terminated character string that is to be written to the file/registry.  Like

char nndata[48] = "Data to be written";

app->WriteProfileString("profile", "somedata",nndata);

Does that help?   Let me know if you have any questions.
0
 

Author Comment

by:peter_b
ID: 2744639
app->WriteProfileString("profile", "somedata",nndata);

ok but i tried to indicate that there are 48 values in the array. So how do I add all the 48 ?
int i;
for (i = 0; i < 48; i++)
{
app->WriteProfileString("profile", "somedata",nndata[i]);
}

or how ?
will they be in one string ? (hmm i just see nndata is a float what to do then ?)

0
 
LVL 22

Expert Comment

by:nietod
ID: 2744693
Your loop would work, but each time it sets the value, it overwrites the old value, so the first 47 value are all lost and only the last value is saved.

>> will they be in one string ?
No.  You can create a long string that has all those values concatenated together (in whatever format you want) and write that string 1 time.

>> (hmm i just see nndata is a float what to do then ?)
You can't write a float directly to the file/registry.  this is only for writting text.  You can convert the float to an ASCII string that _represents_ the float's value in ASCII digits.  Then you can write this string to the file.  You can use sprintf() to convert the float to a string that represents it.

like

char S[20];
double D = 123.456;
sprintf(S,"%6.4f",D);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:peter_b
ID: 2744745
tell me when to stop please as you allready answered my question but as a beginner i am happy if i can learn something.
if i understood it goes like this ??

int i;
float nndata[49] = "";
for (i = 0; i < 48; i++)
{
nndata[49]= nndata[49] + nndata[i]);
}
String newnndata;
sprintf(newnndata,"%6,4f",nndata[49])
app->WriteProfileString("profile", "somedata",newnndata);

"%6,4f" <-- what is this ?
not sure if my concatenate is a concatenate :)
0
 
LVL 22

Expert Comment

by:nietod
ID: 2744860
This is VERY basic C programming concepts.   If you don't understand it, you probably need to spend some time studying an introductory C programming text.  Then when you understand the language, try to program in windows in the language.  Trying to learn windows programmin and try to learn C/C++ programming are two very difficult tasks.  it is best to do them seperately, rather than at the same time.

>> float nndata[49] = "";
No.  if it is an array of floats, it cannot be initialized to a string literal like "".  Only to floating point values.

>> nndata[49]= nndata[49] + nndata[i]);
This adds up all the numbers in the array and stores the total in the last one.  Is that what you want?  Do you want the total value to be stored in the file?  or d you want all 48 values to be stored?   (Note also that it stores the total in the 50th position in the array, but there are only 49 positions that are valid, so this is also an error.)

>> "%6,4f" <-- what is this ?
sprintf() generates a string that represents the value in the floatingpoint number (or whatever is passsed to sprintf().)  These are standard formatting codes that tell sprintf() how you want the string it gererates to look.  These are explained in any C text book.
0
 

Author Comment

by:peter_b
ID: 2744986
Well you are right but as I do this for fun i just want to achieve a goal some programming piece to work. Now for example i am modifying a small app a friend wrote (he has no time to work on it). If I am able to save some data to the registry and recover them I am happy. Much more fun than to read examples of virtual cashing mashines, even if it would take 1,5 minutes for a pro like you and a week for me.
Hope you are not offended if i keep on asking stupid questions in the C/C++ section that seems to be yours :) .


0
 
LVL 22

Expert Comment

by:nietod
ID: 2745082
>> you are not offended if i keep on asking
>> stupid questions
I am not offended and answering questions is why we are here, but I really do think you are going about it the wrong way.  You need to learn C/C++ first (or another language), then windows.  Learning them both at the same time is asking too much of anybody.

In addition, looking over example code is not the best way to learn either.  You are missing VERY basic concepts--like chapter 1 stuff about C.  That is why you really need to start out with a good tex book or two.
0
 

Author Comment

by:peter_b
ID: 2745142
"C++ how to program" i guess from the PAQ ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2745175
That is a good one for the basics--although there are many others.  It definitely doesn't do well in the advanced features, but that shouldn't matter to you for at least a year.  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

840 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