[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

WriteProfileString trying to save an array to registry ...

Posted on 2000-04-24
9
Medium Priority
?
633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

649 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