📄 mfile.c
字号:
/*********************************************************************
* File: mfile.c
* Author: Embest J.Zhao 2005.2.21
* Desc: file function
* History:
*********************************************************************/
#include <stdio.h>
struct sFile
{
char szLetter[20];
};
int f_nMemb = 5;
int main(int argc, char *argv[])
{
FILE *pFile; /* file pointer */
size_t size;
int nTmp;
char cTmp;
char *pMode = "a+"; /* open or creat file */
struct sFile sWbuf[f_nMemb]; /* file buf */
struct sFile sRbuf[f_nMemb]; /* file buf */
/* if input file name*/
if(argc < 2)
{
printf("please scanf the file name\n");
exit(0);
}
/* open file, or creat one if not exist*/
if((pFile = fopen(argv[1], pMode)) == NULL)
{
printf("open error\n");
exit(0);
}
/* write file */
nTmp = 0;
for(cTmp = 'a'; cTmp < 'f'; cTmp++)
{
sprintf(sWbuf[nTmp].szLetter, "Letter : %c", cTmp);
nTmp++;
}
size = fwrite(sWbuf, sizeof(struct sFile), f_nMemb, pFile);
printf("write done.\n");
/* reopen file, read data */
if((pFile = freopen(argv[1], pMode, pFile)) == NULL)
{
printf("reopen error\n");
exit(0);
}
size = fread(sRbuf, sizeof(struct sFile), f_nMemb, pFile);
printf("read:\n");
for(nTmp=0; nTmp < f_nMemb; nTmp++)
printf("Buf[%d] = %s\n", nTmp, sRbuf[nTmp].szLetter);
/* close file */
fclose(pFile);
/* delete file */
if((nTmp = remove(argv[1])) == -1)
{
printf("remove error\n");
exit(0);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -