|
Here is the last modification of the code.
It fulfills the task to be able to reinitialize the array, actually passing a pointer with new data to called function.
The "test function" process / role was immaterial, as long as correct pointer with correct data was received. .
All replies were generaly helpful, which I appreciate.
Thanks.
Cheers
int *pDataArray[32];
int a[] = {55, 1, 2, 3};
int iTestIndex = 0;
memcpy(pDataArray, a, sizeof(a));
do {
cout << "index " << dec << iTestIndex; cout << " array 0x" << hex << +a[iTestIndex] << endl;
}while (iTestIndex++ != sizeof(a)/4);
iTestIndex = 0;
do {
cout << "index " << dec << iTestIndex; cout << " pDataArray a " << hex << +pDataArray[iTestIndex] << endl;
}while (iTestIndex++ != sizeof(a)/4);
int b[32] = {4, 5, 6};
memcpy(pDataArray, b, sizeof(b));
iTestIndex = 0;
do {
cout << "index " << dec << iTestIndex << endl;
cout << " pDataArray b " << hex << +pDataArray[iTestIndex] << endl;
}while (iTestIndex++ != sizeof(b)/4);
|
|
|
|
|
No, I am afraid it is still wrong. You have the following line of code:
int *pDataArray[32];
That creates pDataArray as an array of integer pointers, not an array of integers. And what is the purpose of this variable, since you never do anything useful with it? Maybe if you actually explained what problem you are trying to solve we could make some useful suggestions.
Also in the expressions sizeof(a)/4 , it is better to use sizeof(a)/sizeof(a[0]) . Then if a is changed to some other type, the calculation will still be correct.
|
|
|
|
|
/*Write a programme to check a password if it has an uppercase letter, a digit and a special symbol. (I have provided what I have done and I am not getting the output as required. Need explanation on where I messed it up.)*/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
int i;
int tuna;
do{
printf("Enter a password:%c \n", tuna);
scanf(" %c", &tuna);
} while( tuna != (isupper(tuna), isalpha(tuna), isdigit(tuna)) );
return 0;
}
|
|
|
|
|
I see several things wrong with your approach: 1) The first time through the loop, tuna is uninitialized so the printf() statement is going to print an incorrect character, 2) The scanf() statement is expecting to receive a char (%c ) but you are giving it the address of an int , 3) The isupper() , isalpha() , and isdigit() functions return a non-zero value if the parameter is an uppercase alphabetic letter, and zero otherwise. You are then comparing this to tuna . While syntactically correct, it is nonsensical, 4) If your password is to hold numbers, letters, and symbols, the password type should not be an int , but should probably be a string .
Consider something like:
int reqd = 0;
char pwd[32];
printf("Enter a password: ");
scanf("%s", pwd);
for (int x = 0; x < strlen(pwd); x++)
{
if (isupper(pwd[x]))
reqd |= 0x1;
else if (isalpha(pwd[x]))
reqd |= 0x2;
else if (isdigit(pwd[x]))
reqd |= 0x4;
}
if (reqd == 0x07)
printf("Requirements have been met.\n");
else
printf("Requirements have NOT been met.\n");
"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
|
|
|
|
|
I didn't get the logic behind "reqd" in the if else part. Can you please explain?
|
|
|
|
|
I presume this is for a class and I suspect you have not been taught bit manipulation. Unless you learn about it yourself, you probably do not want to hand in a solution that uses it.
|
|
|
|
|
jschell wrote: Unless you learn about it yourself, you probably do not want to hand in a solution that uses it. Good point. I didn't think through my offering well enough.
"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
|
|
|
|
|
You could (possibly) simplify to something like:
int upper = 0;
int alpha = 0;
int digit = 0;
...
if (isupper(pwd[x]))
upper = 1;
else if (isalpha(pwd[x]))
alpha = 1;
else if (isdigit(pwd[x]))
digit = 1;
...
if (upper == 1 && alpha == 1 && digit == 1)
printf("Requirements have been met.\n");
else
printf("Requirements have NOT been met.\n");
"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 24-Dec-18 9:19am.
|
|
|
|
|
Your code is entering a character (singular) then checking it.
You need to enter a word (multiple characters) and THEN check that entire word for one character of each type.
|
|
|
|
|
Message Closed
modified 22-Dec-18 11:53am.
|
|
|
|
|
Hex 1A (equivalent to Ctrl-Z) is an end of file byte in a text file. You need to change your code so that you open the file in binary mode.
|
|
|
|
|
My worker thread is passing message to the mainframe window with PostMessage.
There is a situation when the PostMessage fails with the ERROR_NOT_ENOUGH_QUOTA error (and sometimes just not fails, but the message is not handled)
That thread does not call PostMessage a lot, maybe 4, 5 times in all when it is used.
There is someone else that PostMessage and I have a hard time figuring out who/what, even if the messages are system messages or our own.
What would be the best way to track down unruly messages that fills the message queue ?
=========================
Problem found.
Recent modifications created an update loop.
Thanks.
I'd rather be phishing!
modified 20-Dec-18 11:37am.
|
|
|
|
|
Maximilien wrote: My worker thread is passing message to the mainframe window with PostMessage. What type of messages (e.g., status)?
Maximilien wrote:
That thread does not call PostMessage a lot, maybe 4, 5 times in all when it is used. Then something else is hitting the queue's 10,000 limit.
Maximilien wrote:
What would be the best way to track down unruly messages that fills the message queue ? Is your main thread blocked such that it is unable to process messages in its queue?
"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
|
|
|
|
|
The main Application/UI thread is not blocked, I can still interact with it and manually stop the worker thread.
The message is to trigger a function in the MainFrame that will set an event (SetEvent).
The handler for the MESSAGEID id is never called. (breakpoint never triggered); so the event is never triggered.
(I know the INFINITE is not the best idea, but it is approved)
My pseudo-code is something like that :
Worker Thread:
void f(CWnd* p)
{
p->PostMessage(MESSAGEID, 0, 0 );
const DWORD dwEvent = WaitForMultipleObjects(NB_EVENT_REGISTERED, ghEventList, FALSE, INFINITE);
}
Main UI thread.
ON_MESSAGE(MESSAGEID, OnMESSAGEID )
LRESULT CMainFrame::OnMESSAGEID (WPARAM wParam, LPARAM lParam)
{
SetEvent(ghEventList[0]);
}
I'd rather be phishing!
|
|
|
|
|
See PostMessageA function | Microsoft Docs[^] for details of this error. Itmay be that something in your code is getting in a loop under certain conditions. Use your debugger to find the culprit.
|
|
|
|
|
i am not certain what to look for in the debugger.
That's my problem.
I'd rather be phishing!
|
|
|
|
|
You need to add some debug code to check every time you call PostMessage.
|
|
|
|
|
Yes, that's what I thought.
I'd rather be phishing!
|
|
|
|
|
I love you. (in a completely professional way).
Merry Christmas.
I'd rather be phishing!
|
|
|
|
|
Ooh, that's a bit unexpected.
|
|
|
|
|
Well,
Just a few years ago my advice would be to use WinDbg and inspect the message queue. However believe it or not many of those fields have been removed from the public symbols on Windows 8.1 and above. Welcome to the age of security via obscurity.
The queue to nowhere
You could probably add some temporary debug code that checked for the ERROR_NOT_ENOUGH_QUOTA and responded by hooking the window and empty the queue by looping a call to the GetMessage function and dumping/printing all of the messages. Or maybe just call GetQueueStatus function and get an overview.
Best Wishes,
-David Delaune
|
|
|
|
|
I am posting this here because I had no luck elsewhere.
Since it is really NOT C/C++ question I like to provide details when somebody
answers. I have high regards for this forum , but from experience elsewhere I hesitate to waste forum and mine time with details and then get no response.
I hope it is understandable and nobody takes an offense.
I like help with analysis of this call, starting with the "command" macro.
I have basic understanding of ioctl and I am successfully implementing this call to send data.
I am unable to receive data and like to go thru the command macro expansion to gain understanding how it supposedly works. Since the main macro expands to more macros and I get lost...
Again - I'll provide details / links etc. to whomever responds.
Cheers
Vaclav
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
|
|
|
|
|
What is to know it is obvious what it is and does .. it writes an SPI block command field index 1 (rx_buf), to the SPI driver.
I would also warn you that macro uses sizeof struct spi_ioc_transfer and it can not be used raw in a C++ program .. it will fail dramatically.
This is mandatory if you wish to use that header in C++ as that is a linux C base file.
extern "C" {
#include <linux/spi/spidev.h>
}
The alternative is to change the header file, you did this dance earlier.
This is one of those things when you start mixing C++ and C, C is it's own language and is not 100% compatible with C++ which has gone it's own way with some syntax. They are getting less and less compatible and so the general recommendation is compile C files with a C compiler and bring them in at the link stage. Other than that take a lot of care with C header files.
In vino veritas
modified 18-Dec-18 12:19pm.
|
|
|
|
|
Thanks Leon,
I have no issue writing the data. I just do not get how the initial command gets to read the data.
However, I just discovered that I can use Eclipse to step thru the macro.
But that is now immaterial since another "discovery" uncovered that I am coding for SPI and the hardware is set for 3 or 4 wire "serial communication" not even close to SPI.
I think I'll shelve the local LCD/TFT and start coding for remote - bluetooth - keyboard and real monitor.
Maybe some day I'll find small LCD/TFT with REAL SPI and not these "cellphones" surplus modules I have been fighting with.
Subject temporary inactive.
Have a great summer down under. We are freezing in Huston!
Cheers
Vaclav
|
|
|
|
|
When you get back if it isn't SPI (which is both 3 and 4 wire BTW) it will be MIPI display interface.
Drivers again in the linux driver
Display Serial Interface - Wikipedia[^]
In vino veritas
|
|
|
|