Support Board
Date/Time: Sat, 01 Mar 2025 10:02:17 +0000
[Programming Help] - sc.ReadFile doesn't work.
View Count: 586
[2021-09-26 17:00:05] |
User253985 - Posts: 23 |
Below is sample code I used to read a file. It doesn't work. Can't see what I'm doing wrong. if (sc.Index == sc.ArraySize - 1) { int FileHandle; sc.OpenFile("D:/SierraChart/Data/Lines_EURUSD.csv", n_ACSIL::FILE_MODE_OPEN_EXISTING_FOR_SEQUENTIAL_READING, FileHandle); if (sc.OpenFile("D:/SierraChart/Data/Lines_EURUSD.csv", n_ACSIL::FILE_MODE_OPEN_EXISTING_FOR_SEQUENTIAL_READING, FileHandle)) { sc.AddMessageToLog("File Opened", 1); } char* Buffer; unsigned int BytesRead = 0; sc.ReadFile(FileHandle, Buffer, 250, &BytesRead); sc.AddMessageToLog(Buffer, 1); sc.AddMessageToLog("BytesRead", 1); std::string bytes = std::to_string(BytesRead); SCString Bytes = bytes.c_str(); sc.AddMessageToLog(Bytes, 1); sc.CloseFile(FileHandle); } MESSAGE LOG Chart: EURUSD[M] 60 Min #2 | Study: Get Plot Profiles | File Opened | 2021-09-26 17:50:37.936 * Chart: EURUSD[M] 60 Min #2 | Study: Get Plot Profiles | | 2021-09-26 17:50:37.936 * Chart: EURUSD[M] 60 Min #2 | Study: Get Plot Profiles | BytesRead | 2021-09-26 17:50:37.936 * Chart: EURUSD[M] 60 Min #2 | Study: Get Plot Profiles | 0 | 2021-09-26 17:50:37.936 * I would prefer to use a C++ while loop but that causes a CPU exception. |
[2021-09-26 17:55:49] |
User907968 - Posts: 833 |
Your problem is here 'char* Buffer;' You actually need to allocate space for the buffer, for example: char* buffer = new char[bufferSize];
memset(buffer, 0, bufferSize); ..... ..... ..... delete[] buffer; or char buffer[512]
ACSIL Interface Members - Functions: sc.ReadFile() Date Time Of Last Edit: 2021-09-26 17:56:12
|
To post a message in this thread, you need to log in with your Sierra Chart account: