|
Nowhere in your code can we see the defintion of "m_Schutzwall" it would be useful
Are you sure you don't have two, m_Schutzwall's it's quite common to that and easy to miss.
If you turn the compiler up to W4 maximum warning it will tell you if m_Schutzwall is hidden by a local copy.
It's dead simple to do something silly with scope like this .. try it
int m_Schutzwall = 1;
int j;
for (j = 1; j < 10; j++){
int m_Schutzwall = j + 2;
}
Do a search for in files for "m_Schutzwall" and look at all the uses.
In vino veritas
|
|
|
|
|
Is it possible that the array int Schadensnummer[] establishs a copy of the member variable of the class RestonaGuldon_Gegner[0]?
The class is global, the variable m_Schutzwall is public.
The class is capsulated in an array.
I dont see a solution so far. it couldnt be that i have to give the array of the class in its own function. i think i forgot something, but i still cant see it.

|
|
|
|
|
addition:
i feel like an idiot. Maybe i am one.
There must be everything allright.
It just misses a ">=" in the function instead of a ">", because the variable is equal 1.
So the entrypoint is never beeing reached. I ll change it and then we ll see.
Thank you so far, i hope i just gave you an evening with something to smile about.
Thanks.
|
|
|
|
|
The title of this thread suggests you are dealing with some function that is returning an array of int s, yet your Basistrefferermittlung() function is simply returning a single int . Is that intentional?
"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
|
|
|
|
|
Some issues:
static int Einschlagsnummer;
Is never default initialized.
Some code paths return nothing so whatever is in [e]ax gets returned, which may be 1.
If Trefferchance is <= 80 and m_Schutzwall > 5, it will return 1 for each iteration up to five. However, you stated that m_Schutzwall is 1 which means it's never decremented to zero since the test is for m_Schutzwall > 1, not m_Schutzwall >= 1. This suggests that the return value is likely what happens to be in [e]ax.
now nitpicking:
int Zufallstreffer;
Zufallstreffer=rand()%99+1;
int Trefferchance;
Trefferchance=rand()%99+1;
Why not initialize the variables in the declaration of them?
Why
m_Schutzwall=m_Schutzwall-1; instead of --m_Schutzwall;
|
|
|
|
|
I would like to make a simple program: it gets 2 strings as input, and outputs everything between them. For example, for input 'a' , 'b' , output is:
a b
for input 'a' , 'zz' , output is:
a b c ... x y z aa ab ac ... ax ay az ba bb bc ... bx by bz ... za zb zc ... zx zy zz
What is the most efficient way to do it in C?
|
|
|
|
|
There is no efficient way to do it you have to do a brute force roll of each character in each row.
It's a standard odometer setup roll a column, when that is complete move the next column 1.
Essentially it's just two functions roll character, roll next column a character.
The roll next column will on occasion call itself because rolling one column needs to roll the next and next etc (watch an odometer on a car roll)
As this is usually homework for a programming unit I will give you one of the functions, you need to do the other
void RollCharacter (char* MyStr, unsigned short Pos) {
while (MyStr[Pos] <= 'z') {
printf("Permutation string = %s\r\n", MyStr);
MyStr[Pos]++;
}
}
char TestStr[10] = { 0 };
TestStr[0] = 'c';
RollCharacter(TestStr, 0);
The column roll is fractionally harder but not much.
In vino veritas
|
|
|
|
|
I should also say there is a generic form of counting used in encryption that uses sets of characters to numbers.
It isn't fast to code because it requires loops with modulo and divides but it gives you a count in a set of restricted characters or characters in any order.
Consider a set of characters abcABC and that was the digit order like 1,2,3,4,5,6
So counting 0 = a, 1 = b, 2 = c, 3 = A, 4 = B, 5= C, 6 = aa, 7 = ab, 8 = ac, 9 = ba etc
The code to display a count sequence is done like this but I would not call it efficient
static char CodeSet[6] = { 'a', 'b', 'c', 'A', 'B', 'C'};
void CovertCountToCode(char* Buf, unsigned short BufSize, unsigned long Count) {
if ((Buf) && (BufSize)) {
BOOL notComplete = TRUE;
unsigned short column = BufSize - 2;
memset(Buf, 0x20, BufSize);
Buf[BufSize - 1] = '\0';
do {
unsigned short digit = Count % _countof(CodeSet);
Buf[column] = CodeSet[digit];
column--;
if (Count >= _countof(CodeSet)) {
Count /= _countof(CodeSet);
Count--;
} else notComplete = FALSE;
} while ((notComplete) && (column > 0));
}
}
void CountInCode(unsigned short MaxCount) {
char Buf[10];
unsigned short i;
for (i = 0; i < MaxCount; i++) {
CovertCountToCode(Buf, _countof(Buf), i);
printf("Code string = %s\r\n", Buf);
}
}
CountInCode(50);
In vino veritas
|
|
|
|
|
Efficient in terms of speed or lines of code?
If the latter, create a string buffer and then manipulate it until it is greater than the end.
|
|
|
|
|
Hi,
As part of the application development, we need to launch the Printing Preferences window programmatically for the given printer.
We tried using DocumentProperties() API with fmode as DM_IN_PROMPT.
With this we are able to launch the Printing Preferences of V3 Printers.
When we tried for the V4 Printers, we are getting the standard UI provided by the Microsoft, but the custom UI provided by the manufacturer is not displayed.
Is there any way to launch the custom UI of V4 Printers programmatically?
Your valuable answers are highly appreciated.
Best Regards,
PurnaReddy
-- modified 25-Oct-16 0:55am.
|
|
|
|
|
I think you need to talk to the manufacturer, we have no idea what a V4 printer is.
|
|
|
|
|
r[1000];
*r = (int *) malloc ((n+ 1) * sizeof(int));
but if I use int *r then also it doesn't passes properly .Should I use structure?
The problem should take input like
division-3
input of price-1,5,8
and give rod cutting whereas there are three iteration which should be one r=0;
and the maximum price for this division should be 8 but the result comes 1677218
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<limits.h>
int sum=0;
int max(int a, int b)
{
return(a>b)?a:b;
}
int cut_rod_aux(int price[], int n, int r[])
{ int i;
if(r[n]>=0)
{
return r[n];
printf(" %d\n",r[n]);
}
if (n==0)
{
sum=0;
}
else
{
sum =100000;
for( i=1; i<n;i++)
{
sum=max(sum, price[i]+cut_rod_aux(price, n-i,r));
printf("%d \n",sum);
}
}
r[n]=sum;
return sum;
}
int cut_rod(int price[], int n)
{ int i,r[1000];
*r = (int *) malloc ((n+ 1) * sizeof(int));
for( i=0; i<n;i++) {
r[i]=100000;
printf("i=%d\t r=%d \n",i,r[i]);
}
return cut_rod_aux(price,n,r);
}
int main()
{ int arr[100],i, N;
printf("Enter the number of length that will be divided\n");
scanf("%d", &N);
for ( i = 0;i< N; i++) {
printf("Enter price for %d length\n", (i+1));
scanf("%d", &arr[i]);}
printf("output %d \n",cut_rod(arr, N));
return 0;
}
modified 17-Oct-16 3:21am.
|
|
|
|
|
I am assuming your cut and paste failed because as that appears to me that would not compile the r line has no type
Anyhow your malloc is correct the problem is with r
1.) You can't and don't need the array specifier.
2.) You definitely don't dereference the malloc to it ... "*r" means dereference
Anyhow any quick check of creating a dynamic array would give you the correct syntax
int* r;
r = (int *) malloc ((n+ 1) * sizeof(int));
That will allocate n+1 integers holding the allocated array in pointer r.
To access them you then use r[x] where x is the index position in the array.
It's your responsibility to release the memory when you are done
free(r);
In vino veritas
|
|
|
|
|
|
You have declared r As an array of 1000 integers and then try to assign it a malloc 'ed array of elements. That makes no sense.
modified 17-Oct-16 11:07am.
|
|
|
|
|
I think I finally outdone myself.
#1 <strike>In have class member function to assign pointer to structure from another class. No matter what I do I cannot make the compiler happy.
Closes to "solution" was "need to use static" than when using static I got incomplete type, again. Originally this function was global and the pointer in question was also globally accessible ( function); The pointer ends up in globally accessible struct, so this exercise may be futile anyway. One solution may be to move the assigning function, but I am not sure of its use down the line, I am not there yet,
I am about to give up and make the function global and be done with it. </strike>
OK that one is fixed moved the pointer assinge,t function DONE
#2 I access a class function via pointer however the function calls the calling call method in sort of circular fashion. Again because originally the app was classless , flat.
Any suggestion how to solve this issue?
I really like to keep the functions / methods in relations to hardware , each in its own class.
Sorry for being such pest.
Vaclav
void HCD_SetEnumerationStartFunction(void (*ResetEnd)(void))
{
hcd_ControlStructure.ResetEnd = ResetEnd;
}
hcd->HCD_SetEnumerationStartFunction(A_USBD::USBD_GetDeviceDescriptorBegin);
-- modified 14-Oct-16 13:26pm.
|
|
|
|
|
You keep doing this over and over .. think about it
A_USBD::USBD_GetDeviceDescriptorBegin IS NOT AND NEVER WILL be a "void (*) void" function.
It's a class member function and so it will be a "USBD::void(*)void"
If you need to check stuff the search string "Member function pointer" will get you what you need.
However I strongly advise you to stop and think for a minute before you start passing member
function pointers around. If you need to do this a lot you might as well pass the whole class
in as a pointer it is only 4 bytes and save the effort.
Here lets cross connect both classes via class instance pointers
class USDB;
class HCD;
class USBD {
public:
void ConnectHCD (HCD* hcd);
void SomeFunction (void);
HCD* ConnectedHCD;
};
class HCD {
public:
void ConnectUSBD (USBD* usbd);
USBD* ConnectedUSBD;
};
void USBD::ConnectHCD (HCD* hcd) {
ConnectedHCD = hcd;
}
void USBD::SomeFunction (void){
}
void HCD::ConnectUSBD (USBD* usbd) {
ConnectedUSBD = usbd;
}
USBD usbd;
HCD hcd;
usbd.ConnectHCD(&hcd);
hcd.ConnectUSBD(&usbd);
hcd.ConnectedUSBD->SomeFunction();
See each class can freely use it's connect buddy via the connected pointer.
You just need to remember to connect them before you ever attempt to use them as
the pointers will always start as null until set.
Usually if you have to do this you have a basic design flaw but you can do it.
In vino veritas
modified 15-Oct-16 0:38am.
|
|
|
|
|
Thanks Leon,
after good night sleep I figured it out and came to same conclusion - it it all about function pointer, again.
I'll get it eventually.
Cheers
Vaclav
|
|
|
|
|
No worries just remember classes always push a self pointer down to the call stack before any call to a function.
That is something a static function pointer can not do and why it needs special syntax.
If you just think of a class as a glorified C struct that can hold code as well as data and you will have an exact
understanding of what is happening. The code block in two instances of the class run exactly the same code the
only thing that changes is the code pulls back different self pointers which where pushed down to make the call.
So the same code on different class instances changes data in two different memory blocks because "self" changed.
In vino veritas
|
|
|
|
|
Leon,
I did check couple of "assigning pointers to class functions" articles.
I'll need some time to digest it. Pretty strange syntax.
I can see how "function to function" works, my problem is the way the original code was I have to eventually pass the pointer to struct and now it is in "standard" function pointer format ()(*)() . So I can either add a new member into the control struct ( it passes it to the ISR) or figure out how to convert the "member pointer" to it, if there is a need to do that.
So I really need to study this first.
Still makes me wonder why I picked such obscure "feature". Oh well.
Cheers
Vaclav
|
|
|
|
|
So if that is the case you have a structural problem in how you organized code. However don't panic first get the
code running and the easy way to do that is pass the whole class in to functions as a pointer .. it's only 4 bytes.
You can pass the class pointer freely into another class lets say USBD needs HCD
void USBD:: SomeFuncThatNeedsHCD (HCD* hcd){
hcd->SomeHCDFunction();
}
or you can pass it to a static code block, lets say some static block needs HCD access
static void SomeStaticCodeWhoAccessHCD (HCD* hcd){
hcd->SomeHCDFunction();
}
As I said it's a symptom of a structural problem but a class is nothing more than a fancy struct it is
legal to pass the class around as a pointer just like you did the original struct ... We just frown on it
Yes you can even pass the class pointer to an interrupt just make sure it is valid before the ISR uses.
That usually means set it to NULL and the ISR checks for a non NULL value before it uses.
In vino veritas
|
|
|
|
|
Just an update.
After all this messing around, I came to realize it all boils down to "plain" function pointer usage.
I need to pay more attention to hardware instead of software.
I essentially have two processes - one runs the video display and the other collects the video data using hardware interrupt.
And there is the culprit - the hardware interrupts fires via single function pointer, and nothing but function pointer. No members function pointers, no class to class access via pointers - its all pretty much "down the hill" after the type of interrupt is determined.
But I have learn few things and that is much appreciated.
Thanks
|
|
|
|
|
Yes but that is easy to deal with fire the interrupt to a static function then kick it to the object. That solution is trivial.
PSOMECLASS* TheClassObject = NULL;
static void InterruptComesInHere (void){
if (TheClassObject) {
TheClassObject->CallSomeMethod();
}
}
All you have to do once you have your object initialized ready to receive is set the pointer to the created object using the & symbol.
I would disable interrupts while you do the pointer set
All it really does is makes the interrupt a couple of cycles slower. The harder part by far is dealing with the interupts in
windows which is nowhere near as easy as DOS.
I assume this is a windows app and I wonder have you got the interrupt working because that isn't easy on windows 7,8 & 10
Windows uses hardware interrupts internally and does not let applications mess with them. You need to create a write a kernel-mode driver for that which is not trivial.
To be honest in Windows at your level it would be easier to simply create a thread and poll the hardware for data and get rid of the interrupt all together.
If you are trying to do this sort of thing commercially you are better off porting the IO onto a USB because they have raw block transfer mechanisms and the USB interface can be bought off the shelf. If you look up EasyCap for example which sells for about $10-$15 will drag normal S video into windows via the USB using exactly that trick.
In vino veritas
modified 19-Oct-16 14:02pm.
|
|
|
|
|
Hi,
I developed a software presentation. I wanted to distribute it using cd's & dvd's.
But, the problem is piracy.
so, i wanted to know the different kinds of ways to provide security to my software.(presentation).
Please . Help me. i need a solution.
Thankyou
|
|
|
|
|