underjack 1 Newbie Poster

You might not have much luck. Some of those specs are contradictary...

For example, a GTX960m has a TDP of 65W. That means that the battery must provide up to 65 watts of current, and the laptop has to reject 65 watts of waste heat. By comparison, most mobile processors from Intel are 35W TDP parts. This means that there will be a lot of copper heat sinksin the laptop (which make it big and heavy) and the battery life will be much shorter (since the laptop uses so much more power).

That being said...check out companies like Sager. They have laptops with the performance you're looking for. But they run close to your maximum price at the low side, are phat and heavy, use massive ~250 power adapers, you can watch the battery gauge move, and double as space heaters.

fallout4player commented: but switching the graphics to the interegrated graphics allow for longer battery life +1
underjack 1 Newbie Poster

This is highly dependant on the OS you're targeting and how you're interacting with the console. Anything beyond the standard streams is pretty non-portable unless you use an external library.

underjack 1 Newbie Poster

The statement char output[MAX_SIZE]; takes exactly zero instructions to execute...

That is a very naïve assumption. char output[MAX_SIZE]; doesn't directly compile to any instructions where it appears, but if it appears inside any function (including main), it declares an automatic object, which is created on the heap (aka free store) every time the function is called. To quote The C++ Programming Language 3rd Ed by Bjarne Stroustrup, page 145:

A local variable is initialized when the thread of execution reaches its definition. By default this happens in every call of the function and each invocation of the function has its own copy of the variable.

So every time you call the function, the computer must spend clock cycles to set aside unique space on the heap for all automatic variables in the function. Using char * output = new char[MAX_SIZE]; and delete[] char; has the exact same effect. Both use the heap, only difference is that with new , the allocation takes place when new is encountered in the function, and without, the allocations happens when the function is called.

underjack 1 Newbie Poster

And I really wonder how making 'output' a static variable would help between function calls. :-)

Without static, each time the function is called, output will be allocated, then deallocated before the function returns. Making it static means that it is only allocated once, and you don't pay the allocation/deallocation cost when you call the function.

underjack 1 Newbie Poster

Hello,
iam having trouble with reading a text file that contains , [ ]
eg. 3715,4[9]
4356,3[7,3]

char c;
     int events[12][12];//[row][col]
  ifstream infile;
  infile.open("test.txt");
     while (!infile.eof()) 
     {
        for(int j=0;j<12;j++) 
        {
                for(int k=0; k<12;k++) 
                {
                        if(c!=']') 
                        {
                                   infile >> events[j][k];
                                   infile.get(c);
                         }
                         else events[j][k] = -1;
               }
        }
        
        infile.get(c);

     } //end while
     infile.close();

for some reason it doesn't jump out of the k loop. j always stays 0

Thanks.

It worked find in Visual C++ 6, but I know that Vis C doesn't behave correctly with variables declared inside if statements.

Try moving the declaration of j and k outside the loops...this may fix your problem, no guarantees.

char c;
  int events[12][12];//[row][col]
  int j, k;

  ifstream infile;
  infile.open("test.txt");

  while (!infile.eof()) 
  {
    for(j=0;j<12;j++) 
    {
      for(k=0; k<12;k++) 
      {
        if(c!=']') 
        {
          infile >> events[j][k];
          infile.get(c);
        }
        else events[j][k] = -1;
      }
    }
        
    infile.get(c);

  } //end while
  infile.close();
underjack 1 Newbie Poster

I kinda forgot what forum I was in (C++/C), but here is a C version of what someone has already done in C++:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

unsigned long extract_digits(unsigned long x, size_t n, size_t i){
  char * buffer;
  char * output;
  size_t num_digits;
  unsigned long num;

  num_digits = (int) log10(x) + 1;

  if ((n - i) > num_digits) return 0;

  buffer = (char *) calloc(num_digits, sizeof(char));
  if (buffer == NULL) return 0;

  output = (char *) calloc((n + 1), sizeof(char));
  if (buffer == NULL) return 0;

  sprintf(buffer, "%u", x);

  strncpy(output, buffer + i, n);

  num = (unsigned long) atol(output);

  free(buffer);
  free(output);

  return num;
}
underjack 1 Newbie Poster

>"Triangle with Rounded Corners" ? I do not get it.
It's called a joke. Chill out.

A circle has circumference, but a triangle has a perimeter. (Actually, any closed figure has a perimeter)

underjack 1 Newbie Poster

I have a some questions, how is your input filters supposed to work, I see some lines like this:

while (( select != 'Q' ) && ( select != 'q' ) && ( select != '1' ) && ( select != '2' ));

If the user enters the wrong input, the programs goes into a infinite loop...?

underjack 1 Newbie Poster

Here's how I interperted your problem:
Given a list of Words and Numbers:
--Make a numbered list of the words.
--Replace numbers with words from the list.

Instead of a console program, I wrote a program that takes a filename at command line. I expect one word or number per line, and output to the second filename, or the first filename +".new" if only one argument is given.

Other than the file aspect, the algorithm should be pretty straight forward. I used an array of arrays for the strings, and kept how many word are in it with a variable. Max size is hard coded at 4095 words. I have one function to check the array for a word, it returns -1 if it is not found.

This compiles and runs without errors or warnings under Visual C++ 6, should be fine under other compilers.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int find_word(const char ** array, const int size, const char * item)
{

  int i = 0;
  
  while (i < size)
  {
    if (strcmp(array[i], item) == 0)
      return i;
    else
      i++;
  }

  return -1;

}

int main(int argc, char *argv[])
{

  char filename[65536], outputfilename[65536];
  FILE * file;
  FILE * outputfile;
  char buffer[256];
  char * array[4096];
  int size = 0;
  int pos;

  if (argc == 1)
  {
    printf("Not enought parameters!\n");
    return 1;
  }

  if (argc > 1)
  {
    strcpy(filename, argv[1]);
  }

  if (argc > 2)
  {
    strcpy(outputfilename, argv[2]);
  }
  else
  { …