| | |
C++ character overflow help!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 4
Reputation:
Solved Threads: 0
Hi
I am using Visual 6 C++ and try to retrieve a member's all closed trades. i declare a string as below:
char str[8000]={0};
But this declaration is ok and the program work fine if the member's record size does not exceed 8000bytes.
In order to be able to retrieve member's record where total size more than 8000, i have declare as below:
char *str = new char();
This declaration works fine but it hang my server. Whenever i execute this API with this declaration, my MT4 server will hang, and its service cannot restarted. We have to restart the server.
Is there any way or any example where i can return big volume data?
Thanks.
My main code to retrieve data as below:
i am using native dll and cannot use MFC
any advise would be appreciated thanks
I am using Visual 6 C++ and try to retrieve a member's all closed trades. i declare a string as below:
char str[8000]={0};
But this declaration is ok and the program work fine if the member's record size does not exceed 8000bytes.
In order to be able to retrieve member's record where total size more than 8000, i have declare as below:
char *str = new char();
This declaration works fine but it hang my server. Whenever i execute this API with this declaration, my MT4 server will hang, and its service cannot restarted. We have to restart the server.
Is there any way or any example where i can return big volume data?
Thanks.
My main code to retrieve data as below:
C++ Syntax (Toggle Plain Text)
trades=ExtServer->OrdersGetClosed(start, end,userlogins,1, &total); //OrdersGetClosed(const time_t from,const time_t to,const int *logins,const int count,int* total); // check orders for(j=0; j<total; j++) { if(strcmp(GetCmd(trades[j].cmd), "credit")!=0 && strcmp(GetCmd(trades[j].cmd), "balance")!=0) { sprintf(tmp,"%d",trades[j].order); strcat(str,tmp); strcat(str,","); sprintf(tmp,"%d",trades[j].login); strcat(str,tmp); strcat(str,","); FormatDateTime(trades[j].open_time,tmp,sizeof(tmp)-1,TRUE,TRUE); strcat(str,tmp); strcat(str,","); strcat(str, GetCmd(trades[j].cmd)); strcat(str,","); COPY_STR(tmp, trades[j].symbol); _strlwr(tmp); strcat(str, tmp); strcat(str,","); sprintf(tmp,"%.2lf",trades[j].volume/100.0); strcat(str,tmp); strcat(str,","); ToSymExt(tmp, trades[j].open_price, trades[j].digits); strcat(str, tmp); strcat(str,","); FormatDateTime(trades[j].close_time,tmp,sizeof(tmp)-1,TRUE,TRUE); strcat(str,tmp); strcat(str,","); ToSym(tmp, trades[j].close_price, trades[j].digits); strcat(str, tmp); strcat(str,","); strcat(str, ToMoney(trades[j].commission, 2, tmp, sizeof(tmp)-1)); strcat(str,","); strcat(str, ToMoney(trades[j].taxes, 2, tmp, sizeof(tmp)-1)); strcat(str,","); strcat(str, ToMoney(trades[j].commission_agent, 2, tmp, sizeof(tmp)-1)); strcat(str,","); strcat(str, ToMoney(trades[j].storage, 2, tmp, sizeof(tmp)-1)); strcat(str,","); strcat(str, ToMoney(trades[j].profit, 2, tmp, sizeof(tmp)-1)); strcat(str,","); mul=Decimals(trades[j].digits); if(trades[j].cmd==OP_BUY) pips=NormalizeDouble(trades[j].close_price*mul,0)-NormalizeDouble(trades[j].open_price *mul,0); else pips=NormalizeDouble(trades[j].open_price *mul,0)-NormalizeDouble(trades[j].close_price*mul,0); sprintf(tmp,"%d", int(pips)); strcat(str, tmp); strcat(str,","); strcat(str, trades[j].comment); strcat(str,"\n"); } } strcat(str,"end\r\n"); //---- clear HEAP_FREE(trades); trades=NULL; if(strlen(str)==0) return _snprintf(buffer,size-1,"ERROR\r\nNo Orders for %d\r\nend\r\n", userlogin); else return _snprintf(buffer,size-1,"%s", str);
i am using native dll and cannot use MFC
any advise would be appreciated thanks
Last edited by Ancient Dragon; Jan 22nd, 2009 at 12:10 am. Reason: add code tags
>>char *str = new char();
Do you really mean something like [icode]char *str = new char(Size);[/code] so that more than 1 character is allocated???
Can't really tell much from the code you posted because there are several undefined variables -- such as temp.
Do you really mean something like [icode]char *str = new char(Size);[/code] so that more than 1 character is allocated???
Can't really tell much from the code you posted because there are several undefined variables -- such as temp.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: May 2008
Posts: 631
Reputation:
Solved Threads: 103
Can you use vector?
If not, you have a little more work cut out for you, but it can still be done. (I am presuming you have a heap and can allocate memory.)
I can fairly easily imagine a class where you can 'add' a C style string to it and it would keep an array of the strings. When you call the 'add' it could allocate enough space to hold the string and copy it in. It would then store the pointer to the new string in an array of character pointers. If you ran out of entries in the array of pointers, you could allocate a new array of pointers (some number of pointers bigger -- think 50 or 100) and copy the old pointers to it and release the old array.
This would provide functionality similar to vector<string> without using "non-native" code.
Once you have assembled all of the trade data, you would return this new object and the calling code could iterate the strings in the object to access all of the compiled data.
If not, you have a little more work cut out for you, but it can still be done. (I am presuming you have a heap and can allocate memory.)
I can fairly easily imagine a class where you can 'add' a C style string to it and it would keep an array of the strings. When you call the 'add' it could allocate enough space to hold the string and copy it in. It would then store the pointer to the new string in an array of character pointers. If you ran out of entries in the array of pointers, you could allocate a new array of pointers (some number of pointers bigger -- think 50 or 100) and copy the old pointers to it and release the old array.
This would provide functionality similar to vector<string> without using "non-native" code.
Once you have assembled all of the trade data, you would return this new object and the calling code could iterate the strings in the object to access all of the compiled data.
•
•
Join Date: Oct 2008
Posts: 40
Reputation:
Solved Threads: 6
if for some reason you cant use stl, you coulc have buffers that hold up to a set amount;in other words keep a large buffer aside that holds, say 4000 characters, as soon as it is full use the next 4000, and switch back and forth. Aside from having more thant 8000 characters at your disposal, anything more than that has to go somewhere if you are at a hard limit.
![]() |
Similar Threads
- Send data on a serial port (C++)
- convert int to string (C)
- floating point : overflow error (C)
- Sprintf and buffer overflow (C)
- program overwritng the 1st input (C++)
- Help Me Please (C++)
- Prog to list ASCII codes (beginners' stuff) (C)
- C++ Error : opening file a second time for a read (C++)
Other Threads in the C++ Forum
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






