是关于如何进行文件操作的

cancer0713 2008-05-24 04:32:03
比如我分别在两个输入框中输入了信息。要对其进行保存,使下次进入时,在输入框中显示的是保存的内容!请问该如何处理啊?最好能有个程序实例!
...全文
493 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
z1w2p311 2008-09-22
  • 打赏
  • 举报
回复
如果有好多项,自己把所有的项定义在一个大的数据结构里面,然后再一起保存在一个文件里面,读出来的时候对号入座就可以了。
movekoala 2008-09-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Demon__Hunter 的回复:]
首先把输入框的内容存入一字符串里,然后存入一文件里,然后用的时候再从文件读出来~~~~
我记得这些brew自带的例子里有相关的代码,楼主看一下~~~
[/Quote]

用这个方法就可以了
vealan 2008-06-16
  • 打赏
  • 举报
回复
lz,好好看例子吧,csdn的兄弟帮你写程序,老板付你钱?
机智的呆呆 2008-05-26
  • 打赏
  • 举报
回复
首先把输入框的内容存入一字符串里,然后存入一文件里,然后用的时候再从文件读出来~~~~
我记得这些brew自带的例子里有相关的代码,楼主看一下~~~
cancer0713 2008-05-26
  • 打赏
  • 举报
回复
请问,如果需要保存标题和内容,是对其进行分开的保存,还是都保存在一个文件里面啊?如果是保存在一个文件里面,改如何处理啊?
Daemon_neu 2008-05-26
  • 打赏
  • 举报
回复
/*===========================================================================

FILE: FileSample.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions

#include "filesample.bid"

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean FileSample_HandleEvent(IApplet * pi, AEEEvent eCode,
uint16 wParam, uint32 dwParam);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
static boolean FileSample_TestFun(IShell *pIShell, uint32 score);

/*===========================================================================

FUNCTION: AEEClsCreateInstance

DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.

After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().

PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded

pIShell: [in]: Contains pointer to the IShell object.

pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs

ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().

DEPENDENCIES
none

RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.

SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;

if(ClsId == AEECLSID_FILESAMPLE){
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)FileSample_HandleEvent,NULL)
== TRUE)
{
// Add your code here .....

return (AEE_SUCCESS);
}
}
return (EFAILED);
}

/*===========================================================================

FUNCTION FileSample_HandleEvent

DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.

PROTOTYPE:
boolean FileSample_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.

ecode: Specifies the Event sent to this applet

wParam, dwParam: Event specific data.

DEPENDENCIES
none

RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event

SIDE EFFECTS
none
===========================================================================*/
static boolean FileSample_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
AECHAR hints1[18] = {'P','r','e','s','s',' ','S','E','L',' ','t','o',' ','t','e','s','t','!'};
AECHAR hints2[13] = {'T','e','s','t',' ','S','u','c','c','e','s','s','!'};
AECHAR hints3[12] = {'T','e','s','t',' ','F','a','i','l','e','d','!'};

AEEApplet *pAEEApplet = (AEEApplet *)pi;
IDisplay *pIDisplay = pAEEApplet->m_pIDisplay;
IShell *pIShell = pAEEApplet->m_pIShell;

switch (eCode)
{
case EVT_APP_START:
IDISPLAY_ClearScreen(pIDisplay);
IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, hints1,
18, 0, 50, NULL, IDF_ALIGN_CENTER);
IDISPLAY_Update(pIDisplay);
// Add your code here .....

return(TRUE);
case EVT_APP_STOP:

// Add your code here .....

return TRUE;
case EVT_KEY:
switch(wParam)
{
case AVK_SELECT:
if(FileSample_TestFun(pIShell, 50) == SUCCESS){
IDISPLAY_ClearScreen(pIDisplay);
IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, hints2,
13, 0, 50, NULL, IDF_ALIGN_CENTER);
IDISPLAY_Update(pIDisplay);
}
else{
IDISPLAY_ClearScreen(pIDisplay);
IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, hints3,
12, 0, 50, NULL, IDF_ALIGN_CENTER);
IDISPLAY_Update(pIDisplay);
}
return TRUE;
default:
break;
}
default:
break;
}
return FALSE;
}


static boolean FileSample_TestFun(IShell *pIShell, uint32 score)
{

const char *pszfile = "record.dat";


uint32 oldscore = 0;


IFileMgr *pIFileMgr = NULL;


IFile *pIFile = NULL;
int i;


if(ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS){
return EFAILED;
}


if(IFILEMGR_Test(pIFileMgr, pszfile) == SUCCESS){

if((pIFile = IFILEMGR_OpenFile(pIFileMgr, pszfile, _OFM_READWRITE)) == NULL){
return EFAILED;
}

i= IFILE_Seek(pIFile, _SEEK_START, 0);
i=IFILE_Write(pIFile, &score, sizeof(uint32));
i=IFILE_Read(pIFile, &oldscore, sizeof(uint32));


if(score > oldscore){

i= IFILE_Seek(pIFile, _SEEK_START, 0);

i= IFILE_Write(pIFile, &score, sizeof(uint32));
}
}
else{

if((pIFile = IFILEMGR_OpenFile(pIFileMgr, pszfile, _OFM_CREATE)) == NULL){
return EFAILED;
}


i=IFILE_Write(pIFile, &score, sizeof(uint32));
}


IFILE_Release(pIFile);


IFILEMGR_Release(pIFileMgr);

return SUCCESS;
}


873

社区成员

发帖
与我相关
我的任务
社区描述
为开发者提供高通丰富的解决方案及全面技术下载内容。本版以AI人工智能、WoS移动笔记本、XR、IoT 物联网、Auto 汽车、生成式AI等核心板块组成,为开发者提供一个便捷及高效的学习交流平台。
人工智能物联网机器学习 企业社区 北京·东城区
社区管理员
  • Qualcomm开发
  • csdnsqst0050
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧