Solved

WriteProfileString trying to save an array to registry ...

Posted on 2000-04-24
9
601 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 50 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

856 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