Thread: [Problem] C, Mingw32 - arrays impact each other (changing values)

  1. #1
    Registered User
    Join Date
    Jun 2009

    Unhappy [Problem] C, Mingw32 - arrays impact each other (changing values)

    About week ago I decided to make an attept to create multiplayer rpg game in j2me. The game needs server so I use c and mingw32 as compiler. I thought the biggest problem will be network programming as I never tried that before. But the j2me client is connecting nicely I have managed to get multiple connections (sending/recieving data) from the clients to the server. Now i encoutered very strange problem of other kind :|. Maybe i'll paste some declarations:

    const int D_SOCKETS = 16;
    int main(int argc, char **argv) {
    int player_y[65536];
    int bytes_sent[D_SOCKETS];

    > then all of the uses of that variables in the file:
    tymczasowa = ((player_y[sockets[i]])/128);
    buffer2[6]= 128+tymczasowa;
    buffer2[7]= 128+(player_y[sockets[i]])-tymczasowa*128;
    for (i=0;i<65536;i++) bytes_sent[i]=0;
    for (j=0;j<sockets_index;j++) {
    if(sockets[j]!=sockets[index]) {
    bytes_sent[(sockets[j])] += 22;
    } }

    so as can you see this values are non related in any way. But each time
    bytes_sent[(sockets[j])] += 22;
    is executed value of player_y[(sockets[2])]) changes the same way...
    exacly bytes_sent[728] = socket_y[712]...
    Eeah time I change one the other changes to the same value..

    It has some really big arrays so i had to change the stack size to 30mb. I compile it with command:
    g++ -Wl,--stack=31457280 sock.c -o main.exe -lwsock32

    I use libraries:
    #include <stdio.h>
    #include <time.h>
    #include <Winsock2.h>
    #define closesocket close
    I know its only one case if I change some minor things it will dissapear but im sure there is more of these mixups. Its just one that I run into. Please help. I have no idea what to do to fix this permanently. I can email the whole code if it is necessary.

    screenshots from the engine:

  2. #2
    Registered User
    Join Date
    Jun 2009
    ok. I see it now. - out of bounds.. seems like i need break from programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading structured arrays, changing their structure
    By _kevin007 in forum C Programming
    Replies: 6
    Last Post: 05-15-2003, 03:49 PM
  2. Replies: 14
    Last Post: 03-17-2003, 10:07 AM
  3. Assigning values to arrays
    By napkin111 in forum C++ Programming
    Replies: 7
    Last Post: 02-26-2003, 08:52 PM
  4. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM
  5. arrays of int, parsing, changing one element
    By stephanos in forum C Programming
    Replies: 3
    Last Post: 11-22-2002, 10:13 AM