局部代码为:
FILE *fp1;
fp1=fopen("C:/Users/yf/Documents/Visual Studio 2010/Projects/ReadTime/ReadTime/ReadTime.xls","a+"); // fp指针指向文件头部
//fopen打开文件
fseek(fp1, 0, SEEK_END);
//SEEK_END指针定位到最后一个数据
if(fp1 == NULL)
{
printf("打开失败\n");
system("PAUSE");
}
char* str = "\t\n1Text";
fputs(str, fp1);
//fputs添加数据
printf("打开成功\n");
fclose(fp1);//释放指针
system("PAUSE");//防止界面一闪而过
整体代码:上部分属于读取出Excel里面的数据,然后下部分添加数据
#include<stdio.h>
#include "stdlib.h"
#include <Windows.h>
#include <math.h>
#include <atlstr.h>
int main()
{
FILE *fp;
int i,j ;
int da[5][4] = {0} ;
fp=fopen("C:/Users/yf/Documents/Visual Studio 2010/Projects/ReadTime/ReadTime/ReadTime.xls","r"); // fp指针指向文件头部
for(i = 0 ;i < 5 ; i++){
for(j = 0 ;j < 4 ; j++)
{
fscanf(fp,"%d",&da[i][j]);
fseek(fp, 1, SEEK_CUR); /*fp指针从当前位置向后移动*/
}
}
for(i = 2 ;i < 5 ; i++){
printf("i:%d da[i][j]:%d %d %d %d \n",i,da[i][0],da[i][1],da[i][2],da[i][3]);
}
fclose(fp);
FILE *fp1;
fp1=fopen("C:/Users/yf/Documents/Visual Studio 2010/Projects/ReadTime/ReadTime/ReadTime.xls","a+"); // fp指针指向文件头部
fseek(fp1, 0, SEEK_END);
if(fp1 == NULL)
{
printf("打开失败\n");
system("PAUSE");
}
char* str = "\t\n1Text";
fputs(str, fp1);
printf("打开成功\n");
fclose(fp1);
system("PAUSE");
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201211084117964.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzkxNzMzNA==,size_16,color_FFFFFF,t_70