从文件中读取数字,数字用逗号分隔,输出第二大的数字。 求助大佬,这个截取数字部分我这个strncpy函数怎么写呀,或者用什么比较好截取出来呀,求助大佬
#include<bits/stdc++.h>
using namespace std;
int main(){
FILE *fp=NULL,*fq=NULL;
char buff[200];
int a[200]={},k=0;
fp=fopen("C:\\Users\\Desktop\\shu.txt","w+");
fq=fopen("C:\\Users\\Desktop\\second.txt","w+");
fputs("15.6,20,10,8.5,5",fp);
fclose(fp);
fp=fopen("C:\\Users\\Desktop\\shu.txt","r");
fgets(buff,200,fp);
int l=strlen(buff);
int i=l;
while(i>=0){
for(int j=i-1;j>=0;j--){从后向前扫描,遇到,则截取j到i之间的数字
if(buff[j]==','){//扫描到,
char *s=buff[j];
char *ss
strncpy(ss,s,i-j);//复制数字
a[k++]=atoi(ss);//存到数组中
}
i=j-1;
}
}
sort(a,a+k);
cout<<a[k-1]<<endl;
cout<<"成功!"<<endl;
fclose(fp);
fclose(fq);
return 0;
}