hmmm... ok, so is not possible to copy this to another string like I thought?
I can print in my exemple the var SubString and got the exact substring that I want to work, but I can't copy that to a another string? are you sure?
hmmm... ok, so is not possible to copy this to another string like I thought?
I can print in my exemple the var SubString and got the exact substring that I want to work, but I can't copy that to a another string? are you sure?
you can copy, strtok does not do it for you. so you should do it by yourself... and be aware that the original buffer you passed to the strtok was changed
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Are you sure you're going about this the right way?
I mean, you're not that experienced in C (by your admission), and string handling in C quite frankly sucks, what with all the effort you have to put into memory management and making sure the nul terminator is always present and correct.
> "origin" "-256 248 16"
How about finding where this gets converted to numeric form, say where the code eventually does
origin.z = 16;
Then all you need to do is one simple line of
origin.z += 15;
and the job's done.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
is not a bad idea, I'll try to look more into it...
my first solution was only changing a line, and should work if I have the MOD source... I'll see if have something like that in the server/client source, not on the MOD one...
if I find that stuff will be really easy to fix the siamese twins problem.
thanks!
don't have such thing unfortunately... what have was in the DLL part which I can change, but will be ignored when the MOD is loaded...
but I found other interesting stuff in code, what could lead me to another solution...
well, I quit to try find good functions, and done everything by hand... so please take a look at this code:
ok, I know need few funcions of convertions or some other thing must be done in the wrong way... please fix everything that you find not good.Code:static void CM_LoadEntityString (const byte *data, const lump_t *l){ char *game = Cvar_VariableString("fs_game"); int i, j, Tam, TamNew; int PA, PB, PC, PD, PL, L1, Num, Espaco, Aspas; char *p, *ori, *HStr, *NewStr, *FinalStr; char *PartA, *PartB, *PartC, *PartD; cm_numEntityChars = l->fileLen; if (cm_numEntityChars < 1) return; if (cm_numEntityChars > MAX_MAP_ENTSTRING) Com_Error(ERR_DROP, "CM_LoadMap: map '%s' has too large entity lump", cm_map); cm_entityString = Hunk_Alloc(cm_numEntityChars + 1); memcpy(cm_entityString, data + l->fileOfs, cm_numEntityChars); if (!Q_stricmp(game, "arena")){ HStr = cm_entityString; // copy the original string to mine Tam = strlen(HStr); // do string manipulation over cm_entityString i=0; j=0; while (j<Tam){ while (HStr[j] != '}'){ // copy to NewStr each Class NewStr[i] = HStr[j]; i++;j++; } NewStr[i] = HStr[j]; //add '}' to the end of the class p = strstr(NewStr, "info_player"); //see if is a spawn class if (!p){ FinalStr = strcat( FinalStr, NewStr ); //if not, save and go to the next class }else{ //if yes, start the hard work ori = strstr(NewStr, "origin"); //find the origin position // than add +8 (origin" ") to that position, which will reach the numbers of the axis L1=ori+8; //------------------------------------------------- NEED TO CONVERT????!!! // find PartA from 0 to L1 for (PA=0;PA==L1;PA++) //seta parte 1/4 { PartA[PA]=NewStr[PA]; } PL=PA; //creat a new var to control the place in NewStr Espaco=0; //set to have zero spaces count // find PartB from start of numbers until 2nd space for (PB=0;Espaco!=2;PB++) //set part 2/4 { PL++; PartB[PB]=NewStr[PL]; if (PartB[PB]==" ") Espaco++; } Aspas=0; //set to plics to zero count // find PartC which is the Number, until reach next " for (PC=0;Aspas==1;PC++) //set part 3/4 = Num { PL++; if (NewStr[PL]=='"') Aspas = 1; else PartC[PC]=NewStr[PL]; } TamNew = strlen(NewStr); //find the size of NewStr // find PartD from " after number until the end of class for (PD=0;PL==TamNew;PD++) //set part 4/4 { PartD[PD]=NewStr[PL]; PL++; } // Convert to Number Num=PartC; //------------------------------------------------- HOW TO CONVERT????!!! Num += 15; //add 15 NewStr = strcat( PartA, PartB ); // make all 4 parts into one NewStr = strcat( NewStr, Num ); //------------------------------------------------- NEED TO CONVERT????!!! NewStr = strcat( NewStr, PartD ); FinalStr = strcat( FinalStr, NewStr ); // add all NewStr to FinalStr } i=0; //NewStr count to zero j++; NewStr=""; //erase NewStr } cm_entityString = FinalStr; //replace the original by the new altered one } }
thanks a lot!
Last edited by hajas; 06-14-2007 at 08:23 AM.
ok, here with atoi convertion....
about the rest? is everything ok?Code:static void CM_LoadEntityString (const byte *data, const lump_t *l){ char *game = Cvar_VariableString("fs_game"); int i, j, Tam, TamNew; int PA, PB, PC, PD, PL, L1, Num, Espaco, Aspas; char *p, *ori, *HStr, *NewStr, *FinalStr; char *PartA, *PartB, *PartC, *PartD; cm_numEntityChars = l->fileLen; if (cm_numEntityChars < 1) return; if (cm_numEntityChars > MAX_MAP_ENTSTRING) Com_Error(ERR_DROP, "CM_LoadMap: map '%s' has too large entity lump", cm_map); cm_entityString = Hunk_Alloc(cm_numEntityChars + 1); memcpy(cm_entityString, data + l->fileOfs, cm_numEntityChars); // do string manipulation over cm_entityString if game = arena if (!Q_stricmp(game, "arena")){ HStr = cm_entityString; // copy the original string to mine Tam = strlen(HStr); i=0; j=0; while (j<Tam){ while (HStr[j] != '}'){ // copy to NewStr each Class NewStr[i] = HStr[j]; i++;j++; } NewStr[i] = HStr[j]; //add '}' to the end of the class p = strstr(NewStr, "info_player"); //see if is a spawn class if (!p){ FinalStr = strcat( FinalStr, NewStr ); //if not, save and go to the next class }else{ //if yes, start the hard work ori = strstr(NewStr, "origin"); //find the origin position L1=atoi(ori); // converted to number L1 += 8; // than add +8 (origin" ") to that position, which will reach the numbers of the axis // find PartA from 0 to L1 for (PA=0;PA==L1;PA++) //seta parte 1/4 { PartA[PA]=NewStr[PA]; } PL=PA; //creat a new var to control the place in NewStr Espaco=0; //set to have zero spaces count // find PartB from start of numbers until 2nd space for (PB=0;Espaco!=2;PB++) //set part 2/4 { PL++; PartB[PB]=NewStr[PL]; if (PartB[PB]==" ") Espaco++; } Aspas=0; //set to plics to zero count // find PartC which is the Number, until reach next " for (PC=0;Aspas==1;PC++) //set part 3/4 = Num { PL++; if (NewStr[PL]=='"') Aspas = 1; else PartC[PC]=NewStr[PL]; } TamNew = strlen(NewStr); //find the size of NewStr // find PartD from " after number until the end of class for (PD=0;PL==TamNew;PD++) //set part 4/4 { PartD[PD]=NewStr[PL]; PL++; } Num=atoi(PartC); // Convert to Number Num += 15; //add 15 NewStr = strcat( PartA, PartB ); // make all 4 parts into one NewStr = strcat( NewStr, Num ); //------------------------------------------------- NEED TO CONVERT????!!! NewStr = strcat( NewStr, PartD ); FinalStr = strcat( FinalStr, NewStr ); // add all NewStr to FinalStr } i=0; //NewStr count to zero j++; NewStr=""; //erase NewStr } cm_entityString = FinalStr; //replace the original by the new altered one } }
My main doubts...
HStr = cm_entityString;
is this the right way to copy a string? then HStr will have the same value of cm_entityString??
Tam = strlen(HStr);
is this the right way to get the lenght of a string? Tam is a number right?
ori = strstr(NewStr, "origin");
is this the right way to receive the position of the NewStr that have origin??? in this case the position of "o"
ori is a number or a pointer to the number that I want? or how can I get that number?
NewStr="";
is this the right way to empty a string?
any other stuff made wrong in my code?
thanks!
Resume here - http://cboard.cprogramming.com/showthread.php?t=90809
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.