第一个问题:
Debug Assertion Failed! fseek.c
#include<stdio.h>
#include "stdlib.h"
#include <Windows.h>
#include <math.h>
#include <atlstr.h>
#define _T(x) __T(x)
#define MB_OK 0x00000000L
int main(){
FILE *fp = NULL ;
fp = fopen("D:\a.xls","w+t") ;
int i=0;
int j=0;
int lineNum = 0;
//写Excel表格,\n代表换行,\t代表换列
//写第1列
fseek(fp,0,SEEK_SET);
fprintf(fp,"t1\tt2\tt3");//,cGt) ;
if(fp!=NULL)
{
fclose(fp);
}
system("PAUSE");
return 0;
}
出现异常:
然后解决代码:
#include<stdio.h>
#include "stdlib.h"
#include <Windows.h>
#include <math.h>
#include <atlstr.h>
#define _T(x) __T(x)
#define MB_OK 0x00000000L
int main(){
FILE *fp = NULL ;
fp = fopen("D:\a.xls","w+t") ;
int i=0;
int j=0;
int lineNum = 0;
//写Excel表格,\n代表换行,\t代表换列
//写第1列
// fseek(fp,0,SEEK_SET);
fprintf(fp,"t1\tt2\tt3");//,cGt) ;
if(fp!=NULL)
{
fclose(fp);
}
system("PAUSE");
return 0;
}
此时出现问题2:
Debug Assertion Failed! fprintf.c
解决办法:
#include<stdio.h>
#include "stdlib.h"
#include <Windows.h>
#include <math.h>
#include <atlstr.h>
#define _T(x) __T(x)
#define MB_OK 0x00000000L
int main(){
FILE *fp = NULL ;
fp = fopen("D:\a.xls","w+t") ;
if(fp == NULL)
{
printf("打开失败\n");
system("PAUSE");
return 0;
}
int i=0;
int j=0;
int lineNum = 0;
//写Excel表格,\n代表换行,\t代表换列
//写第1列
fseek(fp,0,SEEK_SET);
fprintf(fp,"t1\tt2\tt3");//,cGt) ;
if(fp!=NULL)
{
fclose(fp);
}
system("PAUSE");
return 0;
}
出现打开失败
最后解决,路径不对,用的斜杠不对
#include<stdio.h>
#include "stdlib.h"
#include <Windows.h>
#include <math.h>
#include <atlstr.h>
#define _T(x) __T(x)
#define MB_OK 0x00000000L
int main(){
FILE *fp = NULL ;
fp = fopen("D:/a.xls","w+t") ;
if(fp == NULL)
{
printf("打开失败\n");
system("PAUSE");
return 0;
}
int i=0;
int j=0;
int lineNum = 0;
//写Excel表格,\n代表换行,\t代表换列
//写第1列
fseek(fp,0,SEEK_SET);
fprintf(fp,"t1\tt2\tt3");//,cGt) ;
if(fp!=NULL)
{
fclose(fp);
}
system("PAUSE");
return 0;
}
写入成功
\n代表换行,\t代表换列.