nucleon 114 Posting Pro in Training

Since key_c_xor is an array, it needs an index: key_c_xor[j] = userKeyArray[t]^C[i];

nucleon 114 Posting Pro in Training

err = execve ("./server.c", param, 0); You are trying to run the C file! You have to run the executable.

nucleon 114 Posting Pro in Training

You do not have enough disk space to save the pre-compiled headers (PCH file). Delete some files and try again. It is beside the point that your other files compiled nicely. This problem has nothing to do with your code.

nucleon 114 Posting Pro in Training

I, for one, believe you that it's not homework. So here is a simple implementation using a C array (which I believe was your original requirement). It may not be entirely correct since I wrote it almost as fast as I can type.

nucleon 114 Posting Pro in Training

In this situation you cannot use a reference. Think of a reference type as simply automating the address-taking and dereferencing. So this:

void x (char &a)
{
    a = 'x';
}

int main()
{
    char a;
    x (a);
}

Ultimately means this:

void x (char *a)
{
    *a = 'x';
}

int main()
{
    char a;
    x (&a);
}

If you study the above thoughtfully, you will see why there is no way to use references to do what you want. (Remember that a is "syntactic sugar" for *(a+i), so it involves pointer arithmetic and a manual dereference.)

nucleon 114 Posting Pro in Training

To be fair, presumably by "dos" program he meant "console" program. So now he wants to start programming the windows api. "Programming Windows" by Petzold is a good start, but I believe it uses C and not C++.

nucleon 114 Posting Pro in Training

You would just do this:

void CharArray(unsigned char* arr) {
...
}

int main() {
    unsigned char arr[3];
    CharArray(arr);
}

Which is the most modern (ie c++) way to do this?

C++ is over 20 years old.

nucleon 114 Posting Pro in Training

No. Binary mode simply ensures that all file bytes are put into the buffer as is, with no translation whatsoever. Text mode may, depending on the operating system, translate various bytes. For instance, in windows the usual end of line marker is ascii-13 followed by ascii-10. But when read in text mode, all your program sees is the ascii-10.

nucleon 114 Posting Pro in Training

I read 3 c++ books on dos

Now that you're a DOS expert, the world is your oyster!

nucleon 114 Posting Pro in Training
char buffer[100];
ifstream f;

f.open ("pic.bmp", ios::binary);

// skip header
f.read (buffer, 54);

// read 8 bytes into buffer
f.read (buffer, 8);
weasel7711 commented: Thank you +2
nucleon 114 Posting Pro in Training

You have a mismatch of the two declarations of add.
Change: friend AltMoney add(AltMoney m1, AltMoney m2, AltMoney& sum); to friend AltMoney add(AltMoney m1, AltMoney m2); And change: add(m1,m2, sum); to sum = add(m1,m2);

nucleon 114 Posting Pro in Training

If I set "strip executable" it goes from 464k to 260k. The difference between that and what you get with msvc is probably caused by dev-c++ linking statically while msvc is linking dynamically (so the library routines are not in the exe). There may be a way to make dev-c++ (actually g++) link dynamically too, although I can't make it do so (e.g., adding -shared-libgcc to the linker command line didn't work for me).

nucleon 114 Posting Pro in Training

Presumably it's something under the Project Options: Compiler tab. Perhaps try setting Linker: Strip Executable to yes.

nucleon 114 Posting Pro in Training

You are missing a quote (in red): cout<<"VectorA ^ VectorB = " (VectorA^VectorB)"<<" = "<<(VectorA^VectorB).Magnitude()<<endl;

nucleon 114 Posting Pro in Training

That's one possibility. Better yet, you can put the code in a separate file, list.cpp, which includes list.h. Also your main program file, main.cpp, would include list.h.

So part of list.cpp might look like this:

// list.cpp

#include "list.h"

bool List::empty() {
    return (size == 0);
}

void List::first() {
    if (size > 0) pos = 0;
}

void List::last() {
    if (size > 0) pos = size - 1;
}
nucleon 114 Posting Pro in Training

Depends on your IDE. In Dev-C++ you go to Project Options and set the type to a Console program.

nucleon 114 Posting Pro in Training

The original problem was at one time a couple of years ago my co workers homework, but it is most definitely not mine. I'm just trying to see what this should look like.

That explains why it looks like homework! Here's an example list.h for you:

// list.h

#ifndef _LIST_H_
#define _LIST_H_

class List {
    int pos;
    int size;
    ElementType elem [CAPACITY];
public:
    List();
    List (List &list);
    bool empty();
    void first();
    void last();
    void prev();
    void next();
    int getPos();
    void setPos (int pos_in);
    ElementType getElement();
    void insertBefore (ElementType e);
    void insertAfter (ElementType e);
    void clear();
    friend ostream& operator<< (ostream &os, List &list);
};

#endif
nucleon 114 Posting Pro in Training

All I an think of is to convert your program to a gui program and display the text yourself.

nucleon 114 Posting Pro in Training

LTIME must be either 12 (for hours) or 720 (for minutes), it cannot be 12:00 since that is not a proper C constant. Since you are implying that Tcorr is minutes, make LTIME 720. Then if you need the time in hours and minutes:

hours = stime % 60;
minutes = stime / 60;
nucleon 114 Posting Pro in Training

This is looking more and more like homework. Where did you get the main from?

nucleon 114 Posting Pro in Training

You're trying to compile it as a windows gui program, so it's saying that you're missing WinMain (which is the entry point for such a program). You need to compile it as a console program.

nucleon 114 Posting Pro in Training

Check out SetConsoleOutputCP. I have no idea what the various code pages are, but one may have the symbol you want. Some are listed here.

nucleon 114 Posting Pro in Training

I see you TRIED to use code tags. Good effort. I'm not sure why they didn't work. Here's your code with the undeclared identifier errors fixed. It probably doesn't work correctly (I didn't bother to check that) but at least it will run for you.

#include <stdio.h>

int askflight(int[]);
int addToEcomonyClass(int[]);
int addToFirstClass(int[]);
int seatingapp(void);

int main (void)
{
  seatingApp();
  return 0;
}

int seatingApp(void)
{
  int seat[40]={0};
  int seatnumber;
  askflight(seat);
}

int askflight(int seat[])
{
  int choice, seatnumber;
  printf("Please type 1 for first class\n please type 2 for economy.");
  scanf("%d", &choice);

  if (choice == 1)
    seatnumber = addToFirstClass(seat);
  if (seatnumber == -1)
    printf("The first class flight is full");
  if (choice =2)
    seatnumber = addToEconomyClass(seat);

  if (seatnumber ==-1)
    printf("The economy class flight is full!");
}

int addToFirstClass(int seat[])
{
  int t;
  for(t=0;t<10;t++)
    if (seat[t] == 0)
      return t;
  return -1;
}

int addToEconomyClass(int seat[])
{
  int t;
  for(t=10;t<40;t++)
    if(seat[t] == 0)
      return t;
  return -1;
}
nucleon 114 Posting Pro in Training

It's saying that you can't delete the original "b" anymore because you've lost it's address by assigning a to b, which overwrites the previous address that b was holding. So the last line frees the original a, since b now points to a.

nucleon 114 Posting Pro in Training

What OS?????????????

nucleon 114 Posting Pro in Training

They are all "floating point" types. "double" is basically short for "double float" (but you can't say that). A float is usually 32 bits long whereas a double is 64 bits. A long double can be anywhere from 64 (same as double) to 128 bits.

I hear "C++ from the Ground Up" is good for beginners..

nucleon 114 Posting Pro in Training

Also note that you have to use radians (not degrees) for your angles, so pass = 2 * M_PI / vertex (M_PI is in math.h) .

Alex_ commented: Thank you for telling me about radians! +1
nucleon 114 Posting Pro in Training

Thr program still has a bug, though. You are not zero-terminating the c-string "rev". The best way is perhaps:

int i, j;
        for(i = 0, j = strlen(word) - 1; j >= 0; i++, j--)
            rev[i] = word[j];
        rev[i] = 0; // zero-terminate rev

Note that I changed i <= j, j >= 0 to j >= 0 since that's all it's evaluating to anyway. (I can't think of any reason to use the comma operator in the test of a for loop.)

nucleon 114 Posting Pro in Training

On unix or windows you could use libcurl.

marco: What's the windows one-liner?

nucleon 114 Posting Pro in Training

I didn't mean use a C++ list. Just an array to hold the positions you've discovered. Implement a simple "stack" like the following.

const int SIZE = 5;
const int MAXPOSITIONS = SIZE * SIZE;
struct Position {int x, y;} Position;
Position position[MAXPOSITIONS];
int postop = 0;

int recursive (int grid[][SIZE], int x, int y)
{
  if (not out-of-bounds or grid value 0)

    // Push the position
    if (postop >= MAXPOSITIONS) {
      cerr << "Error: postop\n";
      exit (1);
    }
    position[postop++] = (Position){x, y};

    grid[x][y] = 0;
    ...
}

void returnBlobSize (int grid[][SIZE])
{
  ...
    int n = recursive (grid, x, y);

    // Pop the positions and set the grid values
    while (postop) {
      postop--;
      grid [position[postop].x] [position[postop].y] = n;
    }
}

It may be a good idea to change some names. Change "returnBlobSize" to findBlobs and "recursive" to findBlobAtPoint, for instance.

nucleon 114 Posting Pro in Training

I believe you can put this in main.h:

extern CAMARA camera;
extern OBJECT *obj;  // should probably be a longer name for a global

and then in main.c you just put

CAMERA camera;
OBJECT *obj;
nucleon 114 Posting Pro in Training

Your current method is very inefficient, copying the array over and over. My original solution is also very inefficient (a quadruple loop!).

A better solution would be to add the blob points to a list (in "recursive") and then go through the list to set their number (after the call to recursive in "returnBlobSize").

If you need to pass a copy of the array to returnBlobSize, copy it like so: memcpy (grid2, grid, DIM*DIM*sizeof(int));

nucleon 114 Posting Pro in Training

It is ridiculous to use memset to set a single character! It is also odd to dynamically declare memory (for pass and user) when you could just use automatic variables.

As for LogonUser, you need to declare a HANDLE (not a PHANDLE) to recieve the user token. You pass it to LogonUser (last param) as &h. And you should close the handle (CloseHandle) when you no longer need it.

nucleon 114 Posting Pro in Training

Firstly, you shouldn't mix tabs and spaces or you get badly formatted code.

To solve your problem, it would be easiest to set the array element to -1 instead of 0 in "recursive". This means you will have to change the previous "else if" clause to

else if (copyArray[x][y] == 0 || copyArray[x][y] == -1)
        return 0;

Then in "returnBlobSize" you would do something like this:

for (x = 0; x < 5; x++)
        for (y = 0; y < 5; y++) {
            n = recursive (copyArray, x, y);
            for (int a = 0; a < 5; a++)
                for (int b = 0; b < 5; b++)
                    if (copyArray[a][b] == -1)
                        copyArray[a][b] = n;
        }
nucleon 114 Posting Pro in Training

Use fscanf instead of fgets and strtok. E.g.:

float a, b, c, d;
    int n;
    char str[100];
    while (EOF != fscanf (file, "%d %f %f %f %f %s",
                          &n, &a, &b, &c, &d, str))
        printf ("%d %.1f %.1f %.1f %.1f %s\n", n, a, b, c, d, str);
nucleon 114 Posting Pro in Training

Why does that not work? :/

It works for me. Did you put test.bat in C's root dir? Here's a rewrite that starts it from the desktop.

#include <windows.h>

int main() {
    char path[MAX_PATH];
    GetEnvironmentVariable ("HOMEPATH", path, MAX_PATH);
    strcat (path, "\\Desktop");
    ShellExecute (0, "open", "test.bat", 0, path, SW_NORMAL);
    return 0;
}
nucleon 114 Posting Pro in Training

Well, Borland doesn't do it through magic, so there is a way to do it without their functions. For instance, if you are on Windows you would use SetConsoleCursorPosition instead of gotoxy, GetConsoleScreenBufferInfo instead of wherex and wherey, and SetConsoleTextAttribute instead of whatever you would use to set the color. Let me know if you need more info.

nucleon 114 Posting Pro in Training

wherex, wherey, gotoxy are all Borland extensions. (Do Borland compilers still support them?) You can learn how to do it using the OS functions directly yourself.

nucleon 114 Posting Pro in Training

Here's a fix for your "incompatible pointer type" error.

strings = (char **) malloc (total_str * sizeof( char *));

 for (i = 0; i< total_str; i++){
    strings[i] = (char *) malloc (STR_LENGTH * sizeof(char));
 }

And of course you can malloc an array of structs.
BTW, when you say that each file starts with the number of "columns", do you actually mean "rows", i.e., how many strings, one per line, are in the file?

nucleon 114 Posting Pro in Training

Better yet, use ! or ~

nucleon 114 Posting Pro in Training

The arity and precedence of operators is fixed by their standard usage in C++. So / needs two parameters.

nucleon 114 Posting Pro in Training

Place all the nodes in odd positions before those in even ones. For example, the list {a, b, c, d, e} will become {a, c, e, b, d}

Create two empty lists, listOdd and listEven. Create a bool "toggle" initialized to false. Loop through your original list, placing the element in listOdd or listEven according to "toggle". Toggle "toggle" and continue the loop. Rebuild the original list by appending listOdd and listEven.

nucleon 114 Posting Pro in Training

Still havent been able to solve it. Is it even possible to do this?

There must be a way to do it.
What exactly are you trying to do.
What exactly is it doing wrong.

nucleon 114 Posting Pro in Training

Try SRCCOPY in your first BitBlt. Look into other modes if that doesn't do what you want. Also check out TransparentBlt which allows you to have a transparent rgb color.

nucleon 114 Posting Pro in Training

I don't know if this is the problem but check your variables "handle" and "handle2" everywhere you use them. If it still doesn't work, then what exactly do you want it to do and what is it doing?

nucleon 114 Posting Pro in Training

Your GetMin algorithm looks okay. You should post more code. The problem could be in Smallest4 or with the initialization of your matrix.

nucleon 114 Posting Pro in Training

Also, your lattice values can be 16 or greater, so you get out of range errors accessing table with lattice. Try this to see the problem. (Replaces lines 90 to 98 in your previous listing.)

for (i = 0; i < row; i++)
    for (j = 0; j < col; j++)
        if (lattice[i][j] >= 16)
            printf ("%d\n", lattice[i][j]);
        else
            table[lattice[i][j]][1]++;
nucleon 114 Posting Pro in Training

I assume you expect this idiom to give a number between 0 and row - 1: rand() / (RAND_MAX / row) But in fact it occasionally gives a value of row. This is because RAND_MAX is not evenly divisible by row (i.e., there's a little left over). Here's some empirical proof:

int n = 0, i;
    for (i = 0; i < 100000; i++)
        if (rand() / (RAND_MAX / 5) >= 5) n++;
    printf ("%d\n", n);

Instead change it in all similar places to this which can never be out of range: rand() % row

nucleon 114 Posting Pro in Training

Extraneous semicolons are fouling up your logic. Remove them.

else (trump == "S" || trump == "H"|| trump == "A"
            || trump == "D");{ //Won Enough
        score= 30*(numTricks-6);
    }
    if (trump=="NT");{
        score=20*((numTricks-6)+(10));
    }
StuXYZ commented: well spotted +5
nucleon 114 Posting Pro in Training

You need to increment the array index to point to the next element for each character read. Here's an example.

#include <stdio.h>
#define SIZE 1000

int main()
{
    int c, n, i;
    char a[SIZE];
    FILE *file;

    file = fopen ("filename.txt", "r");
    n = 0;
    while ((c = getc (file)) != EOF)
        a[n++] = c;
    fclose (file);

    for (i = 0; i < n; i++) putchar (a[i]);
}