You have to #include <string> and refer to it as std::string or use a using declaration or directive.
You have to #include <string> and refer to it as std::string or use a using declaration or directive.
could anyone convert my pseudocode to C++? thanks a lot...
Yeah, .c files usually mean it's a C program.
Rename it to be a .cpp (or .cc) file, then see what happens.
Perhaps you need to clarify which language you want to program this in, since you posted on the C++ board, and the first comment you said was 'C'.
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.
I tryed... seams that I can't inclued that... if I do pop thousands of errors.
I'm changing a game, so seams that string is not used, and can't be used.
I think is C++... is Quake 2 Engine.
I'm trying to fix a bug in Quake 2, with the Quake 2 Engine.
if is really in C and not C++, please move this topic to the right place. thanks!
well, I know the cause of this bug and the solution, and I could fix with 2 easy ways, but I can't do it in this MOD because I don't have the MOD source where the exact line can't be changed, so override my fix in the original code (which I have the source) when loaded.
So I need to change in the harder way, changing the positions of the spawnpoints to a little higher when load the maps, and in this funcion below is where the entity list of the map is loaded:
than I need this:Code:/* ================= CM_LoadEntityString ================= */ static void CM_LoadEntityString (const byte *data, const lump_t *l){ 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); }
so will only do the change when the game is "arena" (which means the MOD arena), which is compiling and working...Code:/* ================= CM_LoadEntityString ================= */ static void CM_LoadEntityString (const byte *data, const lump_t *l){ char *game = Cvar_VariableString("fs_game"); 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")){ // do string manipulation over cm_entityString } }
now I need to make that pseudo-code that I created to make this work.
than I started:Code:set working = 1; while working == 1 { if "{" not found{ set working = 0; else{ subs = GetSubstring(String, first {, first }); Str1 = GetSubstring (String[0], subs[0]); Str2 = GetSubstring (subs[size],String[size]); if found (info_player_deathmatch || info_player_start) in subs { find "origin" location; posA = find 3rd space after origin location; posB = find next " after posA; Subs1 = GetSubstring (subs[0],posA); Subs2 = GetSubstring (posB,subs[size]); num = GetSubstring (posA, posB); ToNumber(num) += 15; subs = Subs1 + num + Subs2; ReplaceAll (subs, {, [); ReplaceAll (subs, }, ]); } } } ReplaceAll (String, [, {); ReplaceAll (String, ], });
than I'm receiving this error:Code:/* ================= CM_LoadEntityString ================= */ static void CM_LoadEntityString (const byte *data, const lump_t *l){ char *game = Cvar_VariableString("fs_game"); int working = 1; 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")){ // do string manipulation over cm_entityString while (working == 1){ if (cm_entityString.find_first_of("{"){ working = 0; }else{ // other stuff } } } }
more info about this problem at this linkCode:qcommon\cmodel.c(508) : error C2224: left of '.find_first_of' must have struct/union type qcommon\cmodel.c(508) : error C2143: syntax error : missing ')' before '{'
that's all! anyone could help with that?
here all functions available on Q2E
ok, I'm here now...
seams that I need functions at string.h, I'm trying at google since I don't have the Visual Studio .NET documentation....Code:static void CM_LoadEntityString (const byte *data, const lump_t *l){ char *game = Cvar_VariableString("fs_game"); int working = 1; char *p; 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")){ // do string manipulation over cm_entityString while (working == 1){ p = strchr(cm_entityString, '{'); if (!p){ working = 0; }else{ } } } }
so it's C, sorry... please can you move to C programming? thanks!
Done.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
exist any function that I sent a string, point A and point B, then returns a substring between these points?
I can't find!
thanks!
Heres one I just knocked up. It may not be the best way to do this, but it seems to work:
Code:#include <stdio.h> #define str_size 100 void SubStr(char *str, char *str_bit, int start, int end) { --start; for(int i=start; i<end; i++) str_bit[i-start]=str[i]; str_bit[end-start]='\0'; } int main() { char quit='x'; char str[str_size]; char str_bit[str_size]; int start=3, end=8; fgets(str, str_size, stdin); SubStr(&str[0], &str_bit[0], start, end); printf("%s", str_bit); while((quit=getchar())!='\n'); } /* Test data: 1234567890 Output: 345678 */
strncpy can help
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
I was thinking in do something like this with strtok inside the loop:
correct me if I'm wrong, with that I'll have everything in the String until the first } char copied to that SubString variable.Code:SubString = strtok(String,'}');
than I can work with that substring, and create another variable that will save the new string, bla bla bla....
and when this line be executed again will copy from the next char after last char copied first, until the next }, and goes on...
so in each passage of the loop will copy each entity to that SubString... am I right?
remember, the string will always be like something like this:
thanks again!Code:{"classname" "worldspawn"}{"origin" "-256 248 16""classname" "info_player_deathmatch"}{"classname" "info_player_deathmatch""origin" "248 256 16"}{"origin" "248 -256 16""classname" "info_player_deathmatch"}{"classname" "info_player_deathmatch""origin" "-264 -256 16"}{"origin" "-176 -200 24""classname" "weapon_rocketlauncher"}{"classname" "weapon_rocketlauncher""origin" "-184 192 24"}{"origin" "168 184 24""classname" "weapon_rocketlauncher"}{"origin" "-184 -264 24""classname" "ammo_rockets"}{"classname" "ammo_rockets""origin" "192 -256 24"}{"origin" "184 128 24""classname" "ammo_rockets"}{"classname" "ammo_rockets""origin" "-184 128 24"}{"origin" "216 -192 24""classname" "weapon_rocketlauncher"}{"light" "400""origin" "-8 0 208""classname" "light"}
strtok does not copy strings.
It just puts the null char intead of the delimiter found and returns pointer to the token. This pointer points to some location in the original buffer - not to the copy of the substring
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