I am very new to programming, Thank you for bearing with me. I am in need of kind help to solve the issue I am facing, I need to read strings from an excel file (I am using the famous libxl.h library), store it in memory, and rearrange (with some logic) and send it out to a new excel file.
below is my code.
#include <iostream>
#include <windows.h>
#include <conio.h>
#include "libxl.h"
using namespace libxl;
const wchar_t* s1;
const wchar_t* r64ms[64]; //I intend to create an array of 64 inputs
int main()
{
Book* book2 = xlCreateBook();
if(book2)
{
if(book2->load(L"..\\xxxx.xls"))
{
Sheet* sheetms = getSheetByName(book2, L"Sheet1");
if(sheetms)
{
for (int i=0; i<= 10; i+=1)
{ s1 = sheetms->readStr(i, 1);
r64ms[i]=s1;
std::wcout << r64ms[i]<< std::endl << std::endl;
}
}
}
}
Book* bookout = xlCreateBook();
if(bookout)
{
Sheet* mssheet_out = bookout->addSheet(L"Sheet1");
if(mssheet_out)
{
for (int i=0; i<=64; i++)
{
mssheet_out->writeStr(i, 1, r64ms[i]);
//even if i only have 10 inputs, I guess it doesn't matter//
//and will only send out 10 //
}
}
}
return 0;
}
What I have when I run the program is an error "Unhandled exception at 0x0fb147af (msvcr100d.dll) in ExtractTS.exe: 0xC0000005: Access violation reading location 0x00000000." and the Pointer sends me to this line (see comment line 'this line' below):
size_t __cdecl wcslen (
const wchar_t * wcs
)
{
const wchar_t *eos = wcs;
while( *eos++ ) ; // <<<< This line//
return( (size_t)(eos - wcs - 1) );
}
Regardless I try to print out using 'std::wcout' or I try to writeStr to the excel file, the program stops at that moment and gives me this error.
Can someone please be so kind as to help me? I suspect it is the mistake on the way I created the array on const wchar_t* or something. I have tried to search online and couldn't find similar Question/solution.
Thank you very much for your patience with me!