Salem 5,265 Posting Sage

Congrats on getting going.

Even if i run the setup and ticked the option "add to path", the echo %PATH% command didnt seem to show what i expected.

Yeah, this won't transform the PATH of any existing process.

In increasing annoyance order, you may have to:

  1. Start a new cmd window
  2. Log out and log in again
  3. Reboot the machine
Salem 5,265 Posting Sage

When I run the command "python server.py" on the server pc, it held for a second, then released back to the command prompt.

So did it even give you print("Waiting for a connection...") ?

Consider making your server main like this.

if __name__ == "__main__":
    print('Server Begin')
    main()
    print('Server End')

You can add more prints in the main() function itself to try and diagnose the point of failure.

Your client failed with the timeout because your server isn't running.

A very basic test: At the console prompt on your client machine, type ping 192.168.0.2

Salem 5,265 Posting Sage

https://xyproblem.info/

  • User wants to do X.

Sometime later...

My boss just asked me to create a prototype as proof of concept. There is no specific language/tool I must use

  • User asks for help with Y.

Initially asked...

Have a webpage with a button, when pressed, it will launch a webpage that runs a server side exe (eg, notepad.exe or ribbons.scr), while at the same time run the same exe on the local client pc.

So, if you'd stated your initial requirement rather than asking how to fix your unworkable approach, we might have gotten somewhere.

You want something like this:
https://en.wikipedia.org/wiki/Remote_procedure_call

There are multiple ways of doing this.

Can you be more specific about what your "hardware product" is. Because "can be seen as a notebook computer" suggests it isn't a notebook computer at all, but maybe something akin to a glorified point of sale terminal.

  • Does it have an operating system on it?
  • Are you able to install software on it?
Salem 5,265 Posting Sage

And who's head is in the noose when you mess things up with my enterprise account?

Like for example, bad software gets signed with my key, or your "company" is in an embargoed jurisdiction?

If you need it, buy your own.

Salem 5,265 Posting Sage

https://www.php.net/manual/en/mysqli.select-db.php

I think the key word in all of this is "default".

You can probably do what you want, but you have to refer to each DB by it's own handle.

Using select_db is fine, if you only have one DB and you want to be lazy about referring to it.
So you make it the default DB.

But as soon as you have more than one DB, then forget about select_db and just be explicit about which DB you really want at each transaction.

Salem 5,265 Posting Sage

Back to the guessing games....

https://learn.microsoft.com/en-us/cpp/extensions/string-cpp-component-extensions?view=msvc-170
Lists 3 different namespaces where things called 'String' are present.

using namespace Platform;
using namespace default;
using namespace System;

Or maybe you have your own String implementation, who knows (we don't).

What version of the compiler are you using?

As a test, does this compile without error?
String^ pcname("Barney");

rproffitt commented: Not OP but tag tells c++ but not which one or code shown. I have also run into VC++ 1.5 users that I can't help with. +17
Salem 5,265 Posting Sage

I tried that but I get this error

Prove it - post some code.

You won't believe how many times people claim "I've done X" only to find out many posts later that they haven't done X at all, or they managed to fumble it and do "Y" instead.

Salem 5,265 Posting Sage

Cannot convert parameter 1 from char[16] to system::String ^

You need to convert your char array to a CLI string in the first instance, before trying to pass it onto some other function expecting a CLI string.
https://learn.microsoft.com/en-us/cpp/extensions/string-cpp-component-extensions?view=msvc-170

I don't know why DaniWeb keep on crashing whenever I try to write

On my phone (in two different browsers), the thing in the rounded square is the number of open tabs.

Maybe you have an enormous number of tabs open, and you just ran out of memory.

Salem 5,265 Posting Sage

A couple of things stand out.

First, mysql-connector-python is listed at 8.0.15 on both systems.
Looking on https://pypi.org/project/mysql-connector-python/#history that version was released beginning of 2019 (over 5 years ago!)
The latest release version is 9.0.0

Second, your old system has pyOpenSSL, but there isn't an obvious 'ssl' library on your new system. Maybe the underlying error is that there is no SSL library to use (which it fails to handle), then it complains about not being able to find what it was looking for.

TBH, I'd start with pip --upgrade to get everything up to date (but see below first).
I didn't check how crusty the rest of your modules were.

Do you know about Python virtual envs?
https://docs.python.org/3/library/venv.html
You can create mini environments tuned to your application, without having to worry about whether installing/removing particular packages will trash your whole machine.

Instead of shipping a VM, consider Docker
https://www.freecodecamp.org/news/docker-vs-vm-key-differences-you-should-know/

cored0mp commented: Thanks again! Replied below! +0
Salem 5,265 Posting Sage

I would suggest you do pip list in your working and non-working environments.

It seems that wrap_socket is deprecated (and insecure)
https://github.com/eventlet/eventlet/issues/795

I would have thought your mysql would have depended on the right version to begin with.

cored0mp commented: Replied below, thanks! +1
Salem 5,265 Posting Sage

If your batch size is say 1K, and your user decides to spam you with say 10K+ records, what does it matter to you?

  • flush your existing batch queue
  • loop through the large request 1K at a time and immediately commit to the database using some batch update
  • add the remainder of the request to your batch queue.
Salem 5,265 Posting Sage
  1. Get something working in Python if that's your comfort zone.
  2. Profile it to find out where the bottlenecks are (do not make guesses, find evidence)

For example, if the program is spending a lot of time waiting for I/O (aka the disk), then writing chunks of code in C isn't going to buy much (it will just wait more efficiently).

If it's spending a lot of time talking MySQL, then research alternative methods of driving MySQL. Driving the same methods in C won't fix anything.

How much faster could it be?
Say for example all the input conversion was zero cost. Time how long it takes to dump say 10K records into the MySQL database.
If that time is only marginally faster than doing all the work, nothing will be gained by rewriting chunks in C.

How much faster could you make it?
Turning 1 hour into 55 minutes isn't going to change the way you use the program. You're still going to run it and then go to lunch.
You need an order of magnitude improvement (like hours into minutes) to make it worth doing. Shaving off a few % might be academically interesting, but if your time is someone's $, then think carefully.

Next, what's the payback period?
Say you spend a month (say 150 hours) carefully crafting, debugging and testing the best C version ever.
If you made it 10 minutes faster, you need to run it 1000 times before you see a return on …

cored0mp commented: Thank you, I realize that I must now profile my system. +1
Salem 5,265 Posting Sage

If n is a power of 2, look at the value in binary.
Then look at the binary representation of n-1

Salem 5,265 Posting Sage

In C, there is stdin, stdout and stderr, which are the standard I/O streams.

Call your function something else.

Salem 5,265 Posting Sage

> but I'm saying that there is this IO waiting time, in which although CPU does other useful work.
Yes, other useful work, incrementing the clock() for the other processes which are having useful work done.

If you want sub-second precision, then the OP needs to state which OS/Compiler is being used.

gettimeofday() has microsecond precision, but the accuracy can vary from one machine to another. For example, the usec field could be stuck at zero, and the sec field increments once a second, and it would be within spec (although not so useful). Do NOT expect that the usec field will always tick once per microsecond.

Even queryperformancecounter, or the "raw" RDTSC instruction is not without issues.
http://en.wikipedia.org/wiki/Time_Stamp_Counter

Salem 5,265 Posting Sage

http://linux.die.net/man/3/clock
clock() determines (to some approximation) the amount of CPU time used by a program.
Waiting around for I/O typically does not count.

If you want to measure the amount of elapsed time, as by your watch for example, then use the time() functions.

Salem 5,265 Posting Sage

> This is frowned upon by the DW-community.
But sadly not by "da management".
Too many 1-line pith posting dweebs are allowed to stay for far too long.

I'd like to invite the regulars to join me in the land of the -1's; it's just like shooting fish in a barrel.

Salem 5,265 Posting Sage

Bring it on fool - I've found a new sport.

Rep in the lounge is a toy, but doesn't count for anything.
Rep elsewhere is still a toy, but actually counts.

You like bad apples, well you're going to find a LOT of red ones on all your other posts now.

Salem 5,265 Posting Sage

%c ALWAYS takes the next character, including things like space and newline.

Try say
scanf(" %c",&var)

Salem 5,265 Posting Sage

They're called bit-fields, and they're only allowed inside structures.

And yes, the number tells you how many bits are allocated to each small integer, from which it is easy to work out the valid range.

Salem 5,265 Posting Sage

It would have been nice to let them try.
http://www.daniweb.com/software-development/c/threads/78060

Now all they have to do is ctrl-c, ctrl-v

Salem 5,265 Posting Sage

Sure, write out 2,-6,5 in binary.

> int p:3;
Then take the right-most n-1 bits as the value, and the n'th as the sign bit.
The valid range of p for example is -4 to +3

Salem 5,265 Posting Sage

Well first you can write a program containing 3 functions executed sequentially.

int main ( int argc, char *argv[] ) {
  calculateMean();
  printGreaterThanMean();
  printNearestFactorials();
}

When you can do those things, then worry about the thread issues.

Salem 5,265 Posting Sage

> forgot to add that in sort2.txt it for some reason adds a zero, could this be the problem.
I didn't see anything like that when I ran your code.
And nothing in the code you've posted so far suggests that it would add a zero either.

What's your latest code?

Salem 5,265 Posting Sage

Well first off, you must be using some ancient fossil compiler.

What was the error message exactly? Something like "floating point formats not linked"?

Anyway, cleaned up for the modern world, your code seems fine.
It's just the include files renamed, and int main at the end.

#include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <ostream>
using namespace std;

ifstream infile1,infile2,infile6,infile7;
  int Gnum,amountRead = 0,max_read = 99,i = 0,sn,ii;
  const int maxn = 4200;
  float array[maxn] = {0.00000};
  float num,x = 0,xx;
 void getfloat(),read();
 float sort();
 float sort()
 {
  int j;
  float temp;
  for(i=0;i<amountRead;i++);
  for(i=0;i<amountRead;i++)
  for(j=0;j<amountRead-i;j++)
  if(array[j]<array[j+1])
  {
   temp = array[j];
   array[j] = array[j+1];
   array[j+1] = temp;
  }
   amountRead++;
  for(ii = 0;ii<amountRead;ii++)
  {
  if(array[ii] != 0)
  {
   cout<<array[ii]<<endl;
   xx = array[ii];
   ofstream output14("sort2.txt",ios::app);
   output14<<xx<<endl;
   output14.close();
   }
  }
  }
  void getfloat()
 {
  infile7.open("sort2.txt");
   infile7>>x;///  ERROR HERE
   while(infile7)
   {
    infile7>>x;///  ERROR HERE ALSO
    ofstream output15("sort3.txt",ios::app);
    output15<<x<<endl;
    output15.close();
   }
   infile7.close();
  }
 int main()
 {
  infile6.open("float.txt");
  while(infile6>>array[amountRead]&& amountRead < max_read)
  {
    amountRead++;
  }
  for(i = 0; i < amountRead; i++)
  {
    cout<<array[i]<<endl;
  }
  infile6.close();
  sort();
  getfloat();
 } ///End of main

Results

$ g++ foo.cpp
$ ./a.out 
1.56
0.98
5.78
5.78
1.56
0.98
$ cat sort2.txt 
5.78
1.56
0.98
$ cat sort3.txt 
1.56
0.98
0.98
Salem 5,265 Posting Sage

%d = decimal
%o = octal
%x = hex
Seemed as plausible as anything to me.

dotancohen commented: Thank you! +2
Salem 5,265 Posting Sage

"your code"?

Seems remarkably similar to this 2005 vintage effort on another forum.
http://www.pronetworks.org/forums/c-bug-in-program-t53260.html

Perhaps you should
a) try writing your own code
b) post your actual error messages

Some of us here really don't like the "I found this code, please fix it for me" schtick.

Salem 5,265 Posting Sage

Like I said, SPELLING!

teamstructure();
teamstucture(){

Second one is missing 'r'

Salem 5,265 Posting Sage

> ret = GetFileAttributesEx((LPCWSTR)File.c_str(), fInfoLevelId, &lpFileInformation);
The first problem is you can't just go around casting whatever just to make the compiler STFU. If the function really is expecting a wide string, then simply casting a narrow string pointer just doesn't cut it.
You need a proper conversion of File.c_str() into a TCHAR string.
See http://msdn.microsoft.com/en-us/library/aa269775%28v=vs.60%29.aspx and onwards.

> if(lpFileInformation.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE)
The file attributes is a bit-mask containing many discrete bits (eg. read-only directory).
So you need to use bit masking to test each bit, like so.

if( (lpFileInformation.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE)

As for the remove problem, look up the relevant Win32 API for removing files.

Salem 5,265 Posting Sage

main.obj : error LNK2019: unresolved external symbol "void __cdecl teamstructure(void)" (?teamstructure@@YAXXZ) referenced in function _main
C:\Users\daniel\documents\visual studio 2010\Projects\world cup sim\Debug\world cup sim.exe : fatal error LNK1120: 1 unresolved externals

Assuming say teamstructure.cpp is actually in the project and compiled (do a rebuild all to be sure), then the next thing to check is you've
a) spelled the function name correctly (including case sensitivity)
b) the function is void, returning void

Salem 5,265 Posting Sage

> There's nothing wrong with hacky multi-line macros.
Mmm'kay...
Accidentally "forget" to add the { } around the invocation of the macro.
a) does it still compile
b) does it still work

If your answers are like mine ("yes" and "no"), then perhaps you need another approach.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

@sergent
http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Indentation
I'll comment further when I can stomach reading your code.

> How about something less tricky.
Like for example using a function instead of some hacky multi-line macro.

sergent commented: Thanks lol, I am self-taught programmer so my code doesn't always look pretty. My whole program is much bigger so I just quickly cut & paste small portion of it. +4
Salem 5,265 Posting Sage

Perhaps something like this.

string line;
  while ( getline(file,line) ) {
    istringstream s(line);
    string word;
    while ( s >> word ) {
      cout << line << " ";
    }
    cout << endl;
  }
Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/dd183411%28v=vs.85%29.aspx
It seems to return a number of different values.

Perhaps you should look at/print the other values as well as just checking for DISP_CHANGE_SUCCESSFUL.

It might give you some clue as to where to start looking next.

Salem 5,265 Posting Sage

I'd say such questions belong here -> http://www.daniweb.com/software-development/legacy-and-other-languages/42

Though TBH, you'd be better off finding a forum with an actual specialisation in Objective-C, rather than just relying on a couple of people who might know a couple of things.

Salem 5,265 Posting Sage

I wouldn't mind so much if there were some balance between "good" posts and "bad" posts on the end of dead threads.

But as it stands, the ratio is around 1:999 in favour of bad posts.

Bad posts we see repeatedly on a daily basis.
Good posts - well when was the last time you saw one?

jingda commented: Today:) +0
Salem 5,265 Posting Sage

> Signatures don't show up unless you're logged in.
You know that, I know that.

It's the drive-by idiots who sign up, create a profile, post 10 lines of pith in 10 randomly selected posts and then sod off who NEED TO KNOW IT AS WELL.

Is it mentioned anywhere in the signup - I didn't see anything.
A nice "If you were thinking of creating a profile containing sig-links, posting a few times and then leaving, then DON'T BOTHER joining. Spam is deleted and sig-links do not show up in search engines".

I seem to have reported about half a dozen of them just today (just today mind, I've no plan to keep going with this).

Salem 5,265 Posting Sage

This is my three room adventure game

You add more rooms by editing the enum, and adding an extra row in the room array, and changing a few doors in existing rooms to get to the new room.

You might then consider adding say

struct room {
    char    *name;
    int      next[4];   // N,S,W,E from this location
    object  *objects;   // List of things in this room
}

If this is NULL, there is nothing here.

But perhaps you have

struct object {
  struct object *next;
  enum objType;  // objLamp, objAxe, objKey, ...
  char *name;  // "lamp", "axe", "key"
};

Your player struct also has a list of objects collected, which is displayed when you type "inventory". Picking up and putting down is simply moving from the player object list to the room object list.

When you come to open a door, you can check whether the key exists in the player inventory, IF the door happens to be in the locked state.

And so on...

Salem 5,265 Posting Sage

> and ignore the crazy code-formatting problems:
Sorry, that just gets your post ignored.

Nobody here can be bothered to wade through more than a page full of code that was indented by a dancing parrot.

Good indentation will tell you a lot about where it is going wrong without having to read the detail.

Salem 5,265 Posting Sage

> when you could just create a unique namespace and not worry about it?
But don't all namespace names occupy the same namespace?

No doubt there is more than one package out there which uses say the 'graphics' namespace. Trying to use two packages with badly chosen generic names could be a challenge.

How do you ensure uniqueness, without a central (cumbersome) registry?

For a small price, I suppose using a namespace derived from a domain name would suffice.

Using UUID's may be unique (and free), but it's cumbersome to write using namespace NS_5798323769944ad3b9c7ca3f5079704b; or NS_5798323769944ad3b9c7ca3f5079704b::myFunction();

Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/ms686298%28v=vs.85%29.aspx
Sleep(), without all the verbiage at the start.

Salem 5,265 Posting Sage

Don't forget to mention where else you posted, so that we don't waste OUR time saying what has already been said.

You might be considerate to post a link back here on the SO site.

Salem 5,265 Posting Sage

> Last edited by syria718; 24 Minutes Ago at 09:15. Reason: i cant'n post perfectly sorry,,
It seems you still can't - you still haven't figured out [code]
[/code] tags.
How many hints do you need to do this?

Salem 5,265 Posting Sage

Compare your usage with this example perhaps (IANAWP)
http://msdn.microsoft.com/en-us/library/zaewt3xs%28v=vs.80%29.aspx
Note specifically the MAKEINTRESOURCE

You might also check that AfxGetResourceHandle() is actually returning what you think it should (even though the manual page doesn't indicate any error condition).

Salem 5,265 Posting Sage

> And if you could be very specific.
Kinda ironic, given that your post is about as vague as it is possible to get, and still remain comprehensible English.

How about posting some actual code you TRIED?

FWIW, my first thought is you've screwed up over ANSI/UNICODE and your indiscriminate casting to make the compiler STFU has resulted in you trying to manipulate UNICODE strings (where every alternate byte is \0), as an ANSI/ASCII array of bytes, where all those UNICODE \0's make for some very short strings.

Salem 5,265 Posting Sage

What were YOUR answers?
Then we can correct your mistakes and fill in the blanks.

Whereas at the moment, it looks like begging for some spoon-feeding.

Salem 5,265 Posting Sage

Are we supposed to guess what OS you're using, or what _write is supposed to do?

http://linux.die.net/man/2/write
If it's this "write", then the second parameter needs to be a POINTER to some memory, not the munged result of your calculation.
No wonder it crashes.

Salem 5,265 Posting Sage

How about

int colours[3] = { RED, YELLOW, BLUE };
textcolor(colors[rand()%3] + BLINK);

Now add a loop around that, perhaps more colours in the array and maybe even a gotoxy and you're done.

Salem 5,265 Posting Sage

Looks like this and this, with a new username.

Show us what you managed to figure out so far, so we only have to fill in the gaps (as opposed to giving you everything, which simply won't happen).

kvprajapati commented: +1 +15