|
I am trying to rebuild small data base to improve on my terrible knowledge of pointers.
The array is pretty simple integers representing ASCII code , I do the conversion by casting the int or char to LCD print function for display. Works fine with one problem - one of the int in the array is a REAL number ( 0 thru 9) , not just ASCII representation of a number.
For illustration - the ints are 32 65 73 7 73
The "problem " the index #3 does not read just 7 , but 773.
And the array sizeof is also 3 , and it should be 4.
Majority of the code is just for debug.
I can change the real numbers to ASCII representation but would like to know why is this behaving this way.
Appreciate your help.
Vaclav
<pre><pre
int *pCarrier[sizeof(iRecordIndex)];
for (i = 0; i != sizeof(iRecordIndex); i++)
{
pCarrier[i] = &iRecord[i]; // assign data to pointer
lcd_i2c.setCursor(0, 0);
lcd_i2c.print("Index " );
lcd_i2c.print(i);
lcd_i2c.setCursor(0, 1);
lcd_i2c.print((char) iRecord[i] );
lcd_i2c.setCursor(0, 2);
lcd_i2c.print(iRecord[i] );
lcd_i2c.print(" ");
lcd_i2c.print(*pCarrier[i] );
delay(DELAY);
}
lcd_i2c.clear();
lcd_i2c.print("Database " );
lcd_i2c.setCursor(0, 1);
for (i = 0; i != sizeof(iRecordIndex)+ 1 ; i++)
{
lcd_i2c.print((int)*pCarrier[i] );
delay(DELAY);
}
pre></pre>
|
|
|
|
|
How is iRecord declared and initialized?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Why are you using double dereferencing? It would be much easier to code (and certainly to understand) by using arrays of integers rather than pointers. Something like:
int pCarrier[sizeof(iRecordIndex)]; for (i = 0; i < sizeof(iRecordIndex); i++)
{
pCarrier[i] = iRecord[i];
Or better still just use the elements of the original array, since, presumably, it is a simple aray of integers.
|
|
|
|
|
I have modified the 3 position in the int array to ASCII representation and it worked.
I do not understand why it does not work with int 0 thru 9 in 3rd position.
I have included the database read and that is totally bogus when it fails.
I still do not understand what the sizeof(iRecordIndex) is telling me.
Modifying the iRecordIndex ( adding to it ) does not have any effects.
The record has been initialized - this is first time I am using it and it contains 5 ints and rest of it is all zeroes.
The iRecordIndex is 4 during this test.
PS I had the end test in for loop wrong, but the 3rd index value was still printing wrong on LCD.
<pre lang="c++"></pre>
//iRecord[iRecordIndex]
//iRecordIndex += 3;
int iField[32] = {}; // will need to reinitialize
int *pCarrier[sizeof(iRecordIndex)]; // ponter to field
for (i = 0; i != sizeof(iRecordIndex)+ 1 ; i++)
{
pCarrier[i] = &iRecord[i]; // assign data to pointer
lcd_i2c.setCursor(0, 0);
lcd_i2c.print("Index " );
lcd_i2c.print(i);
//lcd_i2c.print(pCarrier );
lcd_i2c.setCursor(0, 1);
lcd_i2c.print((char) iRecord[i] );
lcd_i2c.setCursor(0, 2);
lcd_i2c.print(iRecord[i] );
lcd_i2c.print(" ");
lcd_i2c.print(*pCarrier[i] );
delay(2*DELAY);
}
lcd_i2c.clear();
lcd_i2c.print("Database " );
lcd_i2c.setCursor(0, 1);
for (i = 0; i != sizeof(iRecordIndex) + 1 ; i++)
{
lcd_i2c.print((int)*pCarrier[i] );
delay(DELAY);
}
|
|
|
|
|
Vaclav_Sal wrote: I still do not understand what the sizeof(iRecordIndex) is telling me.
You have not told us how iRecordIndex is declared and initialized.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Sorry.
Both iRecord and iRecordIndex are declared as int and as class variables and initialized in the start of this loop.
The iRecord is reset for next iDatabaseIndex, but I am not that far in checking the code.
(The record needs to be split into several fields, again of variable length).
I wanted to "do pointers" since the database fields length vary and like to save some memory in ARM processor.
for (iDatabaseIndex = 0; iDatabaseIndex < MAX_DATABASE; iDatabaseIndex++)
{
iRecordIndex = 0;
iRecord[32] = {};
....
|
|
|
|
|
This is probably what you need:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main(void)
{
char str[256] = "32 65 73 7 73";
int *pn = NULL, n = 0;
char* _tsn = strtok(str, " ");
while (_tsn != NULL)
{
int* tmp = new int[n + 1];
if (pn != NULL) memcpy((void*)tmp, pn, sizeof(int) * n);
tmp[n++] = atoi(_tsn);
if (tmp != NULL) pn = tmp;
_tsn = strtok(NULL, " ");
}
for (int i = 0; i < n; i++)
printf("%d ", pn[i]);
printf("\n");
_getch();
return 0;
}
|
|
|
|
|
www.codeproject.com/KB/recipes/csha1/CSHA1-2.1-Source.zip
i downloaded d sha1(a hash algo) code from d given link,but i don't know how to use this zip file to encrypt my msg.
pls help!
|
|
|
|
|
Try asking the author of the article, there's a comment section at the bottom of the article for questions. Did you unzip the files and add them to your project?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Hello there. VC++ part of the visual studio is very slow. Debugging is very slow, choosing and compiling a project is very slow, typing is very slow (sometimes it takes more than one second for a letter to show after its corresponding key was hit).
Why is there so much delay in text editor and other things? (Rest of the visual studio i.e. C# and VB are fine). What could be wrong ??
======================================
Solved - Solution Below
======================================
I just installed the Sql Server Compact Edition and this solved my problem. I don't know whether I should have disabled the related components ORR what I did was the right solution. Any way, thanks all the guys for your input.
This world is going to explode due to international politics, SOON.
modified 12-Aug-15 8:39am.
|
|
|
|
|
Native code doesn't like managed IDE.
Seriously, I have the Expression Edition and see no difference in regards of C# or C++.
|
|
|
|
|
It's a problem for you, I have VS2013 Express and it works fine.
|
|
|
|
|
Same software is installed on another machine but it is working fine there. It is just this machine where it is problematic (c++ only). Do I need to check some settings like graphics or something (though I dont see a reason for it) ?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
It could be any number of things. Maybe your computer has a bunch of add-ins running that is slowing the system down.
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
|
|
|
|
|
Hello there, sorry but am a noob at this..... My question is: is there a python implementation of psola
|
|
|
|
|
Wrong forum.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Hi!
I ran the Activating a Window program and found that it goes in an endless loop, where one of the three states it can switch to will be selected, however none of the close buttons on the message boxes function and the only way I was able to end the program was by use of the Task Manage. I have tried a variety of solutions, but none are worthy. I also notice that even when I use my mouse to react to the message boxes, the message that comes up can be This window has been activated, without the mouse.
This seems pretty dysfunctional in terms of a tool to switch between window, since a method should be possible by which to deactivate and close all the windows shown.
|
|
|
|
|
Member 11432935 wrote: I ran the Activating a Window program You should be talking to the person who wrote it.
|
|
|
|
|
Hi Everyone,
we are developing a simple testing tool for GUI testing using AutomationElement (AE). We want extend it to support VB controls also.
But we can not VB control information using AE. I want use .Net remoting to VB control information. Is it possible?
Regards,
Rajendar.
|
|
|
|
|
Does this have anything to do with C/C++/MFC?
|
|
|
|
|
hi , i want to show the text typed in textbox(form 1)
shown on label(form 2)
heres my code : label2.Text = txtUser.text;
i get a error textbox8 does not exist in current context
modified 16-Jul-15 11:16am.
|
|
|
|
|
Okay, and?
[edit]
This looks like VB, .Net, or Unmanaged code. Regardless, you are in the wrong forum.
[/edit]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 16-Jul-15 11:12am.
|
|
|
|
|
and i get a error
|
|
|
|