this library helps you for using Local File System

lfs_useful.h

Committer:
hirokimineshita
Date:
2015-04-20
Revision:
9:9da7f151616a
Parent:
8:38e295ef7892

File content as of revision 9:9da7f151616a:

#ifndef _LFS_USEFUR_H_20150417_1537_
#define _LFS_USEFUR_H_20150417_1537_

/** @file
 */

/** (int)read_some function :
 * @bref read some member of csv format document in local file and write in arrangement
 * @param f write FILE *(name) 's name
 * @param ar arrangement which you want to get data
 * @param num the number of elements you want to get
 */
void read_some(FILE *f,int *ar,int num){
    double temp;
    for(int i=0; i<num; i++){
        if(fgetc(f)!=',')fseek(f,-1L,SEEK_SET);
        fscanf(f,"%lf",&temp);
        ar[i]=(int)temp;
    }
}

/** (float)read_some function :
 * @bref read some member of csv format document in local file and write in arrangement
 * @param f write FILE *(name) 's name
 * @param ar arrangement which you want to get data
 * @param num the number of elements you want to get
 */
void read_some(FILE *f,float *ar,int num){
    if(fgetc(f)!=',')fseek(f,-1L,SEEK_SET);
    for(int i=0; i<num-1; i++)fscanf(f,"%f,",&ar[i]);
    fscanf(f,"%f",&ar[num-1]);
}

/** (double)read_some function :
 * @bref read some member of csv format document in local file and write in arrangement
 * @param f write FILE *(name) 's name
 * @param ar arrangement which you want to get data
 * @param num the number of elements you want to get
 */
void read_some(FILE *f,double *ar,int num){
    if(fgetc(f)!=',')fseek(f,-1L,SEEK_SET);
    for(int i=0; i<num-1; i++)fscanf(f,"%lf,",&ar[i]);
    fscanf(f,"%lf",&ar[num-1]);
}

#endif