croptree 发表于 2011-9-1 20:47:07

9860 SDK如何读取文本文档

如何把读取的字段赋值给变量呢,,请教!!
#include "fxlib.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
FONTCHARACTER * char_to_font(const char *cFileName,FONTCHARACTER *fFileName)
{
int i,len = strlen(cFileName);
for(i=0; i<len ;++i)
fFileName = cFileName;
fFileName=0;
return fFileName;
}                                                                                                                  
int read_text_file (char ** text)
{
int file_handle;
int len;
FONTCHARACTER font_file_name;
char_to_font ("\\\\crd0\\test.csv",font_file_name);
file_handle = Bfile_OpenFile (font_file_name,_OPENMODE_READ);
/* 检测文件是否创建成功失败时返回值小于零 */
if (file_handle<0)
return -1;
len = Bfile_GetFileSize (file_handle);
*text = (char*)malloc(len+1);
/* 检测申请内存是否成功 */
if (*text==0) return 0;
   Bfile_ReadFile (file_handle,*text,len,0);
   Bfile_CloseFile(file_handle);
   (*text) = '\0';
return 1;
}
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
char * text,* t2;
int i,j,k,x,y;
char str;
double s;
i = read_text_file(&text);
x=1;
y=1;
for (j=0;j<100;j++){
sscanf(text+j,"%c",s);
t2=&s;
if (*t2==0x2c || *t2==0x0a){
   x++;
   y=0;
   continue;
}
if (x>8) break;
if (*t2==0x0D) break;
y++;
locate(y,x);
Print((unsigned char *)t2);
}
while(1){
GetKey(&key);
free(text);
}
return 1;
}
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum){
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section

以上代码是引用刘小饕大侠的,,呵呵,,

croptree 发表于 2011-9-1 20:50:16

test.csv 的内容:
32500,189.12132,5012.141,19526.192,1400,960,32600
32600,243.132321,4962.521,20136.654,960,960,32700
页: [1]
查看完整版本: 9860 SDK如何读取文本文档