get array done for file
This commit is contained in:
parent
9c721e6197
commit
53d6e7ddef
|
@ -1,5 +1,4 @@
|
|||
CC = gcc
|
||||
TARGET = data
|
||||
|
||||
all:
|
||||
$(CC) b2hd.c -o b2hd
|
||||
|
@ -7,7 +6,7 @@ all:
|
|||
#$(CC) power.c -o power
|
||||
#getArray.c fileGestion.c power.c main.c -o main
|
||||
|
||||
./b2hd < ../02400031.TXT > decValues.txt
|
||||
./getArray < decValues.txt
|
||||
./b2hd < ../02400031.TXT > rawData.txt
|
||||
./getArray
|
||||
clean:
|
||||
rm *.txt *.o
|
||||
rm decValues.txt newFile.txt
|
|
@ -1,27 +1,16 @@
|
|||
#include "fileGestion.h"
|
||||
|
||||
void newFileCut(int cutLign, FILE *f){
|
||||
void clearRawData(int N){
|
||||
char buffer[256];
|
||||
for(int i = 0; i < cutLign; i++){
|
||||
fgets(buffer , sizeof buffer , stdin);
|
||||
FILE *f = fopen("newFile.txt","w+");
|
||||
FILE *g = fopen("rawData.txt","r");
|
||||
for(int i = 0; i < N; i++){
|
||||
fgets(buffer , sizeof buffer , g);
|
||||
//printf("Line contaigns: %s" , buffer);
|
||||
}
|
||||
while(1){
|
||||
if(!fgets(buffer,sizeof buffer , stdin)) break;
|
||||
if(!fgets(buffer,sizeof buffer , g)) break;
|
||||
fprintf(f,"%s",buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void copyFile(FILE *f , FILE *g){
|
||||
char buffer[256];
|
||||
while(1){
|
||||
if(!fgets(buffer , sizeof buffer , f)) break;
|
||||
fprintf(g, "%s" , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void replaceFile(int nRow,FILE *g){
|
||||
FILE *f = fopen("newFile.txt","a+");
|
||||
newFileCut(nRow,f);
|
||||
copyFile(f,g);
|
||||
remove("rawData.txt"); rename("newFile.txt", "rawData.txt");
|
||||
}
|
||||
|
|
|
@ -3,6 +3,4 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void newFile(int nRow, FILE *f);
|
||||
void copyFile(FILE *f, FILE *g);
|
||||
void replaceFile(int nRow, FILE *g);
|
||||
void clearRawData(int N);
|
BIN
Code-C/getArray
BIN
Code-C/getArray
Binary file not shown.
|
@ -13,13 +13,14 @@ int **get(int N, int M) /* Allocate the array */
|
|||
return array;
|
||||
}
|
||||
|
||||
void fill(int** p, int N, int M) {
|
||||
void fillRawData(int** p, int N, int M) {
|
||||
int i, j;
|
||||
char buffer[200];
|
||||
char *token;
|
||||
FILE *f = fopen("rawData.txt","r");
|
||||
for(i = 0 ; i < N ; i++){
|
||||
|
||||
if (!fgets(buffer, sizeof buffer, stdin)) break; // condition d'arret de la boucle si fichier fini
|
||||
if (!fgets(buffer, sizeof buffer, f)) break; // condition d'arret de la boucle si fichier fini
|
||||
//printf(buffer);
|
||||
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
|
||||
p[i][0] = atoi(token);
|
||||
|
@ -48,13 +49,16 @@ void freeArray(int** p, int N) {
|
|||
free(p);
|
||||
}
|
||||
|
||||
int main(int argc , char** argv){
|
||||
int **getRawDataArray(){
|
||||
int **p;
|
||||
p = get(nRow, nCol);
|
||||
fill(p ,nRow, nCol);
|
||||
fillRawData(p ,nRow, nCol);
|
||||
//print(p, nRow, nCol);
|
||||
FILE *g = fopen(,"w"); //here to find the good one
|
||||
replaceFile(nRow,g);
|
||||
freeArray(p ,nRow);
|
||||
clearRawData(nRow);
|
||||
//freeArray(p ,nRow);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void main(int argc , char** argv){
|
||||
getRawDataArray();
|
||||
}
|
|
@ -3,4 +3,4 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int getArray(int nRow, FILE *f);
|
||||
int **getArray();
|
700011
Code-C/newFile.txt
700011
Code-C/newFile.txt
File diff suppressed because it is too large
Load diff
|
@ -1,15 +1,15 @@
|
|||
#include "power.h"
|
||||
#include "getArray.h"
|
||||
|
||||
double power(int tab[nRow][8]){
|
||||
double power(int **p){
|
||||
double periode = 1 /freqEch;
|
||||
double power[8];
|
||||
for(int i = 0; i < 8; i++){
|
||||
int j = 0;
|
||||
double res = 0;
|
||||
while(1){
|
||||
if(!tab[j+1][i]) break;
|
||||
double aire = ( pow(tab[j][i],2) + pow(tab[j+1][i],2) ) / 2 * periode;
|
||||
if(!p[j+1][i]) break;
|
||||
double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * periode;
|
||||
res += aire;
|
||||
j++;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ double power(int tab[nRow][8]){
|
|||
return *power;
|
||||
}
|
||||
int main(int argc , char** argv){
|
||||
FILE *f = fopen(argv[1],"r");
|
||||
double pw = power(getArray(nRow,f));
|
||||
double pw = power(getArray());
|
||||
printf("%d" , pw);
|
||||
}
|
File diff suppressed because it is too large
Load diff
900011
Code-C/save.txt
900011
Code-C/save.txt
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue