69,371
社区成员
发帖
与我相关
我的任务
分享
struct point
{
char num[10];
double x;
double y;
};
point pn[6]; //待判断的6个点
char dust[50];
FILE *read;
read = fopen("欲判断点.dat","r");
count = 0;
fgets(dust,60,read); //fgets 后 文件指针指向下一行开头。
int Line = 1;
while(!feof(read))
{
if(fscanf(read,"%s%lf%lf",&pn[count].num,&pn[count].x,&pn[count].y) == 3)
{
count++;
Line++;
}
else
{
printf("Line %d Error!\n",Line);
}
}
O(∩_∩)O谢谢~
std::ifstream ifs(szFileName, std::ios::in);
if(ifs.fail())
return false;
ifs >> lpTestDataX >> lpTestDataY;
ifs.close();
可以参考一下! FILE *pf;
struct{
char name[16];
double px;
double py;
}p;
pf = fopen("2.c", "r");
while(!feof(pf))
{
fscanf(pf, " %s %lf %lf ",p.name, &p.px, &p.py);
printf("%-10s %-16lf %-16lf\n",p.name, p.px, p.py);
}
fclose(pf);
struct PS {
char no[40];
double x;
double y;
} ps[100];
……
while(1)
{
if (NULL==fgets(pc, 1000, pflIn)) break;
L++;
if (3==sscanf(pc,"%39s%lf%lf",ps[i].no,&ps[i].x,&ps[i].y) {
i++;
} else {
printf("line %d format error:%s",L,pc);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void fun(char *a,char *b,char *s)
{
int i,j;
int c=0;
for (i=0;i<strlen(a);i++)
{
if (a[i]=='\t'&&c==0)
{
c=1;
continue;
}
if (c==1)
{
for(j=0;a[i]!='\t';j++)
{
b[j]=a[i];
}
b[j]='\0';
c=2;
}
if (c==2)
{
for(j=0;a[i]!='\0';j++)
{
c[j]=a[i];
}
c[j]='\0';
}
}
}
int main()
{
FILE *fp;
fp=fopen("1.txt","r");
char msg[40];
char qq[10][41];
char qq1[41];
char qq2[42];
memset(msg,sizeof(msg),0);
int i=0;
int j=0;
while(fgets(msg,sizeof(msg)/sizeof(char),fp))
{
if (i==0){
i++;
memset(msg,sizeof(msg),0);
continue;
}
else{
j++;
strcpy(qq[j],msg);
memset(msg,sizeof(msg),0);
}
}
for (i=0;i<10;i++)
{
fun(qq[i],qq1,qq2);
printf("%s\t%s\n",qq1,qq2);
memset(qq1,sizeof(qq1),0);
memset(qq1,sizeof(qq2),0);
}
return 0;
}
fgets直接读一行
char pc[1000];
FILE *pflIn;
pflIn = fopen("XX.txt", "rb");
fgets(pc, 1000, pflIn);//如果一行的内容小于1000个字节,读到行尾就结束。
while(!feof(pflIn))
{
...///处理代码
fgets(pc, 1000, pflIn);//如果一行的内容小于1000个字节,读到行尾就结束。
}