Sokurenko 42 Junior Poster

No, everyone has them, you need to be patient. Cheer up :)
Just always know that this is c language, there is no magic, if something does not work then you can find out why always. Add as much printf as you can to do that..
Like that

void checkcollision()
{
    float x1 = tanks[0].x;
    float y1 = tanks[0].y;
    float x2 = tanks[1].x;
    float y2 = tanks[1].y;
    float dist = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    float dr = tanks[0].rad+tanks[1].rad;
    printf("dist: %f, radius+radius: %f\n",dist, dr);
    if(1 < 2)
    {
       puts("yes");
    }
    else
    {
       puts("wtf");
    }
    if(dist < dr) ;
    {
        printf("checkcollision read true\n");
        printf("dist: %f, radius+radius: %f\n",dist,dr);
        goback(0); goback(1);
    }
}

thank you. Am I the only one who has trouble seeing small problems in walls of text that comprise code? This is depressing.

Sokurenko 42 Junior Poster

if(dist<dr);
remove semicolon ?
should be or it will do nothing if dist < dr and do nothing on else

    if(dist<dr)
    {
        printf("checkcollision read true\n");
        printf("dist: %f, radius+radius: %f\n",dist,dr);
        goback(0); goback(1);
    }
Sokurenko 42 Junior Poster

did you try binary mode ?
http://www.cplusplus.com/reference/clibrary/cstdio/fread/
it should work very goot if you work with bytes.
for example - read whole file to buffer then run through all bytes and if byte is not 0 output to result buffer

Sokurenko 42 Junior Poster

It looks like it works, please explain better or post file.
Also, yes you should take hex editor to know exactly wat you are dealing with.. If it is not 8bit chars then you need to parse it differently..
check out dragon post
http://www.daniweb.com/software-development/c/threads/254246/how-to-read-unicode-utf-8-binary-file-line-by-line

Sokurenko 42 Junior Poster

this is what it means fifth is null terminator 065 in oct is '5' check ascii table

#include <stdio.h>

int main()
{
   char str[]="S\065AB";
   char strSame[5] = { 'S','\065', 'A', 'B', '\0'};

   printf("str 1 %d \n", sizeof(str));
   printf("str 2 %d\n", sizeof(strSame));
   printf("same ? %d [%s] [%s]",strcmp(str, strSame),str, strSame);   

   return 0;
}
Ancient Dragon commented: nice :) +14
Sokurenko 42 Junior Poster
int a[]={1,2,3,4,5,6,7,8,9,10};

You allocate memmory on stack here and a points to that memmory.
Then pointer b points to that memmory location b=a
i mean now b and a point to same location so you can work with it same as with a

here you can try to print it's addresses to check :)

#include <stdio.h>

int main()
{
   char pcArray[3] = {0};
   char *pcToArray = pcArray;
   printf("pcArray == %x and pcToArray == %x",pcArray,pcToArray);
   return 0;
}
Sokurenko 42 Junior Poster

use

printf("size of char %d size of int %d",sizeof(char),sizeof(int));

bot pointer is always 4 byte no ?

maybe you can try to cast to char ?

by the way where is problem?

strcpy(*rowptr,"d");
    strcpy(*(rowptr+1),"c++");
    printf("ROWPTR+1[%s]",*(rowptr + 1));
    strcpy(*(rowptr+2),"java");
    printf("ROWPTR+2[%s]",*(rowptr + 2));

they print correct, no ?

please see howto allocate memmory for pointer to pointer Click Here took code from there

float **float_values;
//allocate memory for rows
float_values = (float**)malloc(4 *sizeof(float*));
//for each row allocate memory for columns
for(int i=0; i<4; i++)
{
   *(float_values+i) = (float*)malloc(3 *sizeof(float));
}
Sokurenko 42 Junior Poster

@pooh1234qwerty
dont use questions like that, use printf to make shure :) make some test array to test and make it smaller maybe and if it will work in smaller it will work in bigger.
You wrote something , you should understand what you wrote, assumptions is not very good thing in programming and it's not about compiler.
To make code more readable for you and other people name variables to something meaningfull like Schol sayed i dont want to read code where something is l then something does s1 + s2 what is that and no comment
to normal human s1 doesent mean anything
hope this will help you to debug your code :) if no understand comment every line explay what it is and print results out till you have something that you cant explayn and it doesent work

Sokurenko 42 Junior Poster

alternative is malloc
you will locate it on heap instead of stack or calloc effect is same bot you haveto free it after and it can be dinamically changed during execution :)

Ancient Dragon commented: right answer :) +14
Sokurenko 42 Junior Poster

enum or define of possible values and switch no ?

#include <stdio.h>

enum eGprsEnum
{
   GPRS_T = 3,
   GPRS_X = 1000,
};

int iDoStuff(int iId)
{
   int iRet = 0;

   switch(iId)
   {
   case GPRS_T:
      printf("%d",iId);
      break;
   case GPRS_X:
      break;
   default:
      iRet = -1;
      break;
   }

   return iRet;
}

int main()
{
   iDoStuff(3);
   return 0;
}
Sokurenko 42 Junior Poster

@abrarsyed
your program is really sick, bot you did great job if it works, you might learn allot from it :)

Sokurenko 42 Junior Poster

@DeanMSands3

but your post is... not what the OP is asking for.

I passed by value, i did make copy, look link what it is, passing by value Click Here Please

yes i know the details are that i passed constant pointer to constant data, bot the result is exactly same from outside the function, except it stores data on heap and you can dinamically pass more or less data

Sokurenko 42 Junior Poster

`

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

void vIdoPrintArray()
{


}

void vPassByValue(const void * const vData, int iSizeOfElement, int iDataLength)
{
   void *vCopyData = NULL;
   vCopyData = malloc(iSizeOfElement * iDataLength);

   if(vCopyData != NULL)
   {
      int i = 0;
      memcpy(vCopyData, vData, iSizeOfElement * iDataLength);
      //printf("passed by value %s\n",vCopyData);
      while(i < iDataLength)
      {
         //printf("%d",*((int*)vCopyData + i ));
         printf("%d",((int*)vCopyData)[i]);
         i++;
      }
      memset(vCopyData, 0, iSizeOfElement * iDataLength);
   }

   free(vCopyData);
   return;
}



int main()
{
   int  pcBuffer[] = {1,2,3,4,5,6};

   //sprintf(pcBuffer,"%.12d",1234);

   vPassByValue(pcBuffer, sizeof(int), 6);
   //puts(pcBuffer);
   return 0;
}

Bot This could be best solution or best VAR_ARGSClick Here

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

void iPassByVal(char *pcBufferToWorkWith)
{
   puts(pcBufferToWorkWith);

   return;
}

int main()
{
   char pcBuffer[20] = {'W','o','r','k','\0'};
   char pcBufferCopyToPass[20] = {0};

   memcpy(pcBufferCopyToPass, pcBuffer, sizeof(pcBuffer));

   iPassByVal(pcBufferCopyToPass);

   return 0;
}

`

Sokurenko 42 Junior Poster

Another possible solution

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

void vPassByValue(const void * const vData, int iSizeOfData)
{
   void *vCopyData = NULL;

   vCopyData = malloc(iSizeOfData);
   if(vCopyData != NULL)
   {
      memcpy(vCopyData, vData, iSizeOfData);
      printf("passed by value %s\n",vCopyData);
      memset(vCopyData, 0, iSizeOfData);
   }
   free(vCopyData);

   return;
}

int main()
{
   char pcBuffer[20] = {0};

   sprintf(pcBuffer,"%.12d",1234);
   puts(pcBuffer);
   vPassByValue(pcBuffer, sizeof(pcBuffer));
   puts(pcBuffer);

   return 0;
}
Sokurenko 42 Junior Poster
Sokurenko 42 Junior Poster

check conn for NULL, maybe failed to connect ? or result is NULL cause nothing found

Sokurenko 42 Junior Poster

try this ? just check everywhere for NULL where possible :)

row = mysql_fetch_row(result)

while (row != NULL)
{
   for(i = 0; i < num_fields; i++)
   {
      //printf("%s ", row != NULL ? row[i] : "NULL");
      printf("%s", row[i]);
   }
   printf("\n");

   row = mysql_fetch_row(result)
}
Sokurenko 42 Junior Poster

have you considered java ?

WaltP commented: How does that help in passing from C to PHP??? +0
Sokurenko 42 Junior Poster

dont use printf(buffer); to debug

memset(buffer,0,sizeof(buffer);
//fill it with data
for (i=0;i<sizeof(buffer);i++)//print every element
{
    printf("[%c]",buffer[i]);//or printf("[%d]",buffer[i]);
}
Sokurenko 42 Junior Poster

use array index and no need to return nothing, just print name afterwards :)
by the way you are not modifying char* and returning from a function, you are modifying the data that pointer points to and returning pointer to that data