Copy link to clipboard
Copied
When I read txt file during the second development using fdk, I can read all information from txt file,But when finish to read the txt file,FramMaker ocurres serious error.
code:
VoidT GetEffectiveInfo()
{
FILE *fp;
CharT a[10];
StringT page,startTime,endTime;
fp=fopen("C:\\effTime.txt","r");
if(fp!=NULL)
{
while(!feof(fp))
{
//fgets(str,25,fp);
fscanf(fp,"%[^,]%*c",a);
F_ApiAlert((StringT)a, FF_ALERT_CONTINUE_WARN);
}
fclose(fp);
}
}
error information:

Copy link to clipboard
Copied
zhaopeng,
I don't know enough about this to say what is wrong with your code. However, here are two functions which I've used reliably for some time. One uses FDK functions and the other uses C stdio.h stuff. Both return the text file as an F_StringsT array, with each string representing a line from the text file. Maybe this will help you troubleshoot your code.
Russ
//currently a maximum of 2048 characters per line
IntT ws_ReadTextFile(StringT path,
F_StringsT *returnStrings)
{
ChannelT chan;
FilePathT *filepath;
UCharT ptr[1],
uchar[2048];
IntT numRead;
UIntT i = 0;
ws_StrsInit(returnStrings, 0, False);
//convert the path and open the channel (file)
filepath = F_PathNameToFilePath(path, NULL, FDosPath);
if((chan = F_ChannelOpen(filepath,"r")) == NULL)
return False;
//read the first character
numRead = F_ChannelRead(ptr, sizeof(UCharT),
1, chan);
//run this loop, reading character by character until we get to the end
while(!F_ChannelEof(chan))
{ //if we get to a carriage return, let's substitute a line termination escape if(ptr[0] == 13) { uchar = '\0';//and append the UCharT array to the end of the strings array. A line
//currently a maximum of 2048 characters per line
IntT ws_ReadTextFile_2(UCharT *fileName,
F_StringsT *returnStrings)
{
FILE *stream;
errno_t err;
UCharT uchar[2048];
IntT i;
ws_StrsInit(returnStrings, 0, False);
// Open for read (will fail if file "crt_fopen_s.c" does not exist)
err = fopen_s(&stream, fileName, "r" );
if(stream && !err)
{
while ( fgets ( uchar, sizeof uchar, stream ) != NULL )
{
for(i = 0; i < sizeof uchar; i++)
{
if(uchar == 10 ||
uchar == 13 ||
uchar == 0)
{
uchar = 0;
i = sizeof uchar;
}
}
ws_StrsAppend(returnStrings, (StringT)uchar);
}
}
if(stream != NULL)
fclose(stream);
if(err) return False;
else return True;
}
VoidT ws_StrsInit(F_StringsT *strings,
UIntT len,
UIntT deallocateFirst)
{
if(deallocateFirst == True)
F_ApiDeallocateStrings(strings);
strings->len = len;
strings->val = (StringT *) F_Alloc(len*sizeof(StringT), NO_DSE);
}
VoidT ws_StrsAppend(F_StringsT *strings,
StringT newString)
{
//allocate/reallocate the new array
if(strings->len == 0)
{
if(strings->val)
F_ApiDeallocateStrings(strings);
strings->len = 1;
strings->val = (StringT *) F_Alloc(1*sizeof(StringT), NO_DSE);
}
else
{
strings->len++;
strings->val =
(StringT *) F_Realloc(strings->val,
strings->len*sizeof(StringT), NO_DSE);
}
//put the new string on the end
strings->val[strings->len - 1] = F_StrCopyString(newString);
//we're done
return;
}
Copy link to clipboard
Copied
Thank you very much!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more