|
|
|
Try
#include <stdio.h>
#include <string.h>
#define MAX 10
int srch(const char *a[],char *b)
{
int i = 0;
while ( a[i] != NULL)
{
if ( ! strcmp( b, a[i]) ) return i;
++i;
}
return -1;
}
int main()
{
int index;
const char *a[]={"abc","xyz","lmn", NULL};
char b[MAX];
printf("\nplease, enter string to find\n");
if ( fgets(b, MAX, stdin) )
{
for (index = 0; index < MAX; ++index)
if ( b[index] == '\n')
{
b[index] = '\0';
break;
}
printf("string to find '%s'\n",b);
index = srch( a, b);
if ( index != -1 )
printf("string found at index = %d\n", index);
else
printf("string not found\n");
}
return 0;
}
Please note, fgets includes the newline in the string, that's the reason for the clumsy code used to remove it.
|
|
|
|
|
I am typing the text and changing the color using SetSel() and SetSelectionFormat().On clicking ctrl+z single time I need to delete that text.I dont want to remember SetSel() and SetSelectionFormat() operations for undo.
When I do ctrl+z second time, I need to do redo operation?
How to achieve this?
Or How to achieve multilevel undo/redo operations for CRichEditCtrl?
|
|
|
|
|
|
|
char *pinNumber = this->gpionum;
cout << " pinNumber " << pinNumber << endl;
This is what I need - insert char * into char array
char constant + char * + char constant
I CANNOT USE STRING
char *setdir_str ="/sys/class/gpio/gpio"; // + "pinNumber" + "/direction";
the final setdir_str = "/sys/class/gpio/gpioX/direction"
I know how the size the setdir_str and can allocate memory for that.
I have no idea how to concatenate all individual parts of the array WITHOUT using string.
Just char !
Any constructive help would be appreciated,
just remember
NO STRING!
|
|
|
|
|
|
You have to either use std:string or dynamically allocate/reallocate character arrays to add the needed substrings into.
|
|
|
|
|
Just use the standard c string functions like strcpy, strcat or even sprintf to do what you want
Technically you are trying to concat c strings but also looks like you want a int to ascii conversion.
Just messing around here to show sorts of things you can do.
#include <stdio.h>
int gpionum = 1;
char buf[256] = { 0 };
sprintf_s(&buf[0], _countof(buf), "/sys/class/gpio/gpio%d/direction", gpionum);
size_t ss = strlen(&buf[0]) + 1;
char* setdir_str = (char*)malloc(ss);
strcpy_s(setdir_str, ss, &buf[0]);
setdir_str = "/sys/class/gpio/gpio1/direction" in above example
It's all the normal string functions that existed before the string object in c++ existed.
There is also the unicode equivalent of each function if you need them in <tchar.h>
In vino veritas
modified 16-Dec-17 11:18am.
|
|
|
|
|
Thanks Leon.
Exactly what I need.
Simple and clean...
char setdir_str[256];
int n = sprintf(setdir_str, "/sys/class/gpio/gpio%s/direction", this->gpionum);
#ifdef CCC_DEBUG
printf("[%s] is a string %d chars long\n", setdir_str, n);
cout << "direction string " << setdir_str << endl;
#endif
What is interesting the parameter type passed to sprintf has to be %s "string" - not %c.
I sure get mixed up with all these characters / string and string class.
Thanks again
-- modified 16-Dec-17 17:50pm.
|
|
|
|
|
Vaclav_ wrote: What is interesting the parameter type passed to sprintf has to be %s "string" - not %c.
%c is used for a single character.
%s - for the char sequence.
|
|
|
|
|
Read the details - I am passing SINGLE char.
Maybe passing %s includes hidden terminating charterer - hence "sequence ", but the description of the function calls %s a string not a sequence - which makes more sense.
|
|
|
|
|
Vaclav_ wrote: Any constructive help would be appreciated,
First since you are using C++ you should be using 'new'
Steps
1. Call the existing character array A. Call the data to insert S.
2. Determine the size of the NEW array that you need. Add A size plus size of S.
3. Use 'new' to create brand new character array using size from #1. Call this new array X.
4. Determine where you are going to insert the new data.
5. Copy from A into X up to the point where you want to insert
6. Copy all of S into X at the point where you STOPPED in #4
7. Copy the REMAINDER of A (what was left over in A from #4) into X at the point where you STOPPED in #6.
Result is now in X.
|
|
|
|
|
Since this is C++ you should use the string class; that is what it is designed for.
modified 17-Dec-17 3:00am.
|
|
|
|
|
So have a char array:
char* buf="/sys/class/gpio/gpioX/direction"
And set the value at 'X'
*buf+20 = <whatever you="" want="">
|
|
|
|
|
Nice, but than I need to count the pointer where the insertion goes.
Which in my case is constant, so not big issue.
Thanks for your contribution .
Cheers
|
|
|
|
|
You can always count backwards from the end, find the first / and insert the value before that.
String parsing like this, C style, is done a heck of a lot. It is light weight and very quick.
|
|
|
|
|
I have 2 windows, let's say a FileZilla window and a Notepad Window. And I have the FileZilla window is on the top of the Notepad one (like cards; on above the other).
I want to know how could I get the information that the FileZilla window is above the notepad's one ?
I tried GetWindowLong But no chance.
LONG wndState1 = ::GetWindowLong(handler1, GWL_EXSTYLE);
LONG wndState2 = ::GetWindowLong(handler2, GWL_EXSTYLE);
both results is equal to 256.
Is there a trick for that ?
"The Only Limit Is Only Your Imagination."
modified 15-Dec-17 11:52am.
|
|
|
|
|
Try calling EnumDesktopWindows. I think it will give the window handles in their z-order to the callback function. I am not sure about this though. It would be fairly easy to contrive a test app to experiment with it. You might find EnumWindows will do it also. Between the two you should be able to determine what you want. Once you get the window handles in their z order you will have to determine which window is which, likely by their titles.
|
|
|
|
|
|
I need smthing that works with c++.
"The Only Limit Is Only Your Imagination."
|
|
|
|
|
If you can do C++, then you can surely translate from C#. Especially since the functions you need to call are right in the code.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Windows API has the function GetTopWindow
GetTopWindow function (Windows)[^]
From the TopWindow you want walk down thru the chain via GetNextWindow
GetNextWindow function (Windows)[^]
So in your case you want to ask the topWindow of the window that contains both FileZilla window and a Notepad Window. You can then walk along the chain using GetNextWindow and see which is above which just by asking the window title.
Something like this will work
char buf[256];
HWND Wnd = GetTopWindow( );
GetWindowText(Wnd, &buf[0], sizeof(buf));
while (Wnd != 0 && !stricmp(&buf[0], "FileZilla") && !stricmp(&buf[0], "NotePad"))
{
Wnd = GetNextWindow(Wnd, GW_HWNDNEXT); GetWindowText(Wnd, &buf[0], sizeof(buf)); }
if (Wnd == 0) {
}
else {
}
It is equivalent to
EnumChildWindows function (Windows)[^]
However for the simplicity you have it isn't worth setting up the enumeration function.
In vino veritas
|
|
|
|
|
Is there an Api to implement exception handling on function/frame thread basis without the _try _except/_catch statements as that limits me to only certain type of exceptions
It would be nice to have an api on a function or frame Even on a thread basis
The function and the frame saves the programmer from doing unwinding
with AddVectoredExceptionHandler I catch everything but then I have to figure out from which function the exception occurred
Thanks
|
|
|
|