Salem 5,265 Posting Sage

So do you know (for example) how to tell if a number is even or odd?

Do you know how to arrange 3 numbers in order, ignoring the even/odd part of the problem?

Salem 5,265 Posting Sage

Only that "rat" and "tar" are anagrams (and permutations (and palindromes)), but "rta" would just be a permutation.

Salem 5,265 Posting Sage

If each file is taking up to 30 minutes, and you have lots of files, then the total run time is going to be many hours, possibly an overnight job, or even days.

Why do you need a per-second update of progress?

Or why do you have so much "free" time to care about looking at the progress so often of a process which is going to take a long time.

Salem 5,265 Posting Sage

> I found a solution, but sadly in C++
Yeah, there's a lot of "finding" going on.
http://www.daniweb.com/software-development/cpp/threads/374401/1611050

People who go around "finding" code don't seem to be that interested in learning anything. Only in (ab)using the generosity of online forums just to get some free coding done.

Try http://www.vworker.com/ if you're not interested in actually learning, but just interested in getting something done in exchange for money.

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

How about you post YOUR attempt, then we suggest where you might have gone wrong.

As opposed to expecting us to do all the work for you.

Salem 5,265 Posting Sage

Something like this?

char filename[] = "00001234_FILENAME.EXT";
char newfilename[100];
if ( sscanf( filename, "0000%*d_%s", newfilename) == 1 ) {
  // format seems to be as expected
  rename(filename,newfilename);
}
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

> Why does it always return true?!
Why don't you run it in the debugger and find out which path through the code it takes.

I mean, if it always hits line 29, then you're looking in the wrong place.

Salem 5,265 Posting Sage

> ifstream file (filename, ios::in|ios::binary|ios::ate);
The output stream needs to be binary as well.

Salem 5,265 Posting Sage

Sounds like a good place to start.

Salem 5,265 Posting Sage

So look through build_all.sh for where gcc is called.

Or perhaps where a variable (say CFLAGS) is set to a number of gcc options.

Either way, make sure the program is compiled with -g

Salem 5,265 Posting Sage

Well if you just want to compare, then writing the dates out in yyyymmddhhmmss format allows you to use normal string comparison functions.

Or you could parse out the data, and use mktime() to give you some integer representation of time, which again can be compared to see which is before/after.

Salem 5,265 Posting Sage

So apart from adding "using namespace std;", have you done anything else to the code?

That is, apart from simply doing copy and paste from here
http://www.scribd.com/doc/51963645/bank-cpp

> I am not sharp in programmin
No, and unless you actually buckle down and start writing YOUR OWN PROGRAMS, you never will be.

Salem 5,265 Posting Sage

Well that depends on how much you plan to change before it is regarded as "not Linux anymore".

Linus may have written version 0.1 as a solo effort about 20 years ago, but it's been a cast of 10,000+++ to get it to where it is today.

Salem 5,265 Posting Sage

Meanwhile, progress over here -> http://forums.devshed.com/c-programming-42/errors-converting-c-to-c-835932.html

If you're going to cross post (not that it is recommended), at least have the courtesy to include reference to other help so we don't go over all the basics AGAIN!.

Salem 5,265 Posting Sage

http://lmgtfy.com/?q=circular+linked+list
Even that little bit took more effort than your useless topic title and brief text.

http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

Salem 5,265 Posting Sage

It's a bit strange to ask a question, then mark it as solved.

For your question, I would suggest not using scanf() at all, and instead only use fgets() to read the input into a buffer, then use sscanf(), or any other string functions, to extract what you need from the buffer.

scanf() is too tricky to make it robust in anything except the simplest of programs.

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's hard to know where to begin.

I suppose we could begin with where you copy/pasted it from.
http://www.scribd.com/doc/48581406/New-Text-Document

Try writing your own code for a change, as opposed to

- find random crap on the web
- find it doesn't compile (gosh, shock, horror)
- dump the sorry mess on a random forum hoping someone else will spend time fixing it up while you go party.

In short - not going to happen.

Salem 5,265 Posting Sage

http://www.google.co.uk/search?q=thesis+title+help
See, the problem here, is that DW is the #1 link at the moment.

So in they come "feeling lucky", only to get a face-full of wet fish.

But the self-reinforcing meme has been planted, with YET ANOTHER post with the magic search engine keywords to ensure that more of them will come, with more of the same posts, leading to better and better ranking in search engines, which (well, you get the picture).

The forum needs to be PURGED of all these lame-assed 1-posters who cannot think for themselves, then the problem would attend to itself, because no more would be smart enough to get here under their own initiative.

Salem 5,265 Posting Sage

Or perhaps "Learn C++ in 24 hours from a thread that is 5 YEARS OLD".

It's remarkable how many threads on DW get dug up on the anniversary of their original post date. I'm convinced the search here doesn't care about years, but latches onto the month and day like some blood-starved leech.

And no, you can't learn C++ in 24 hours, or 21 days, or some other ridiculous time frame. In 24 hours, you'll be able to tell the difference between a C++ program and a hole in the ground, but that's about all. You certainly won't be a competent programmer of anything more substantial than "hello world".

Read this -> http://norvig.com/21-days.html

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

Who would have thought this thread would have lasted 4 years and got 2000 replies?

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

> Also I've searched my entire C reference book (written by Herbert Schildt)
Perhaps you want a better book.
http://www.catb.org/jargon/html/B/bullschildt.html

Salem 5,265 Posting Sage
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

US presidential elections are basically like games of poker.

The person with the biggest pot of money has an advantage, but they can still screw it up, or get called by one of the under dogs with a "bluff".

The under dogs sooner or later have to go "all in" just to stay in the game; if they "win", they get a boost from the loser, or they're out of the game.

Not that losing is that much of a hardship (there is no shelter for failed presidential candidates). The size of the electioneering pot they exited the game with goes along way to bargaining a position in whatever new administration eventually forms.

Oh, and I think this thread will win the award for the "most replies after being marked solved".

Salem 5,265 Posting Sage

Same answers as your other thread.
http://www.daniweb.com/software-development/cpp/threads/373847

Are you even listening?

Salem 5,265 Posting Sage

So compile it with gcc -g prog.c Then run the program as

gdb a.out
<<snip wordy gdb output>>
run

When it crashes, use 'bt' to print where it happened.
'up' and 'down' navigate the stack
'print' can print variables

Find out what variable contained a garbage value, and work from there.

Salem 5,265 Posting Sage

Your best bet is to visit the maintainer site for that package, and
a) see if there are any updates
b) read the FAQ to see if it's a common problem with known answers
c) ask on THEIR forum, as there you will find the MOST people with the MOST experience of using it.

Joining random technical forums in the hope of getting lucky enough finding someone who knows about it isn't really the way forward.

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

> Is there a way around this?
Yes, get a 64-bit processor with at least 8GB of memory, and an OS/Compiler that can actually take advantage of all that hardware.

Or you figure out how to factorise your problem into say 8 iterations with 500x500x500 blocks (assuming that will fit - it's still 0.5GB).

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

Well it will be a lot easier to answer if you tell us which OS you're using.

Salem 5,265 Posting Sage

Like I said, SPELLING!

teamstructure();
teamstucture(){

Second one is missing 'r'

Salem 5,265 Posting Sage

Here's an idea Dani (and no, not EVERY forum has such a problem as this one seems to have). But then again, not every forum has an internet marketing(scam) forum which is the big honey pot for those kinds of twits.

Here, visit this -> http://www.stopforumspam.com/
Better yet
- sign up
- install whatever plugin is necessary to STOP people joining who have been black-listed already
- install whatever plugin is necessary so that when someone is banned for spamming, they get blacklisted in a whole load of other places as well.

Salem 5,265 Posting Sage

You mean like the latest fuck-tart angelina88 with the SMS spam all over the forum?

Salem 5,265 Posting Sage

Perhaps something like this?

printf("Enter a number between 10 and 50: ");
if ( scanf("%d", &myint) == 1 && myint >= 10 && myint <= 50 ) {
  // do stuff
}

But if you wanted to really make it bomb-proof, you would need to use fgets() to read a line of input into a buffer, and use strtol/strtoul to convert the string to an integer, and check the return results of both functions.

Note: scanf conversions do NOT detect overflow/underflow, which the strto.. functions will.

Salem 5,265 Posting Sage

> How could I compare the efficiency between them?
Use a profiler.

In big-O terms, the algorithm is the same, so the complexity is the same.

Generally speaking, iterative solutions tend to be more efficient, but you also have to write more code to make it work.

Simple recursive functions (and a smart compiler) may turn out to be iterative for free.
http://en.wikipedia.org/wiki/Tail_call

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.