get array done for file
This commit is contained in:
parent
9c721e6197
commit
53d6e7ddef
|
@ -1,5 +1,4 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
TARGET = data
|
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(CC) b2hd.c -o b2hd
|
$(CC) b2hd.c -o b2hd
|
||||||
|
@ -7,7 +6,7 @@ all:
|
||||||
#$(CC) power.c -o power
|
#$(CC) power.c -o power
|
||||||
#getArray.c fileGestion.c power.c main.c -o main
|
#getArray.c fileGestion.c power.c main.c -o main
|
||||||
|
|
||||||
./b2hd < ../02400031.TXT > decValues.txt
|
./b2hd < ../02400031.TXT > rawData.txt
|
||||||
./getArray < decValues.txt
|
./getArray
|
||||||
clean:
|
clean:
|
||||||
rm *.txt *.o
|
rm decValues.txt newFile.txt
|
|
@ -1,27 +1,16 @@
|
||||||
#include "fileGestion.h"
|
#include "fileGestion.h"
|
||||||
|
|
||||||
void newFileCut(int cutLign, FILE *f){
|
void clearRawData(int N){
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
for(int i = 0; i < cutLign; i++){
|
FILE *f = fopen("newFile.txt","w+");
|
||||||
fgets(buffer , sizeof buffer , stdin);
|
FILE *g = fopen("rawData.txt","r");
|
||||||
|
for(int i = 0; i < N; i++){
|
||||||
|
fgets(buffer , sizeof buffer , g);
|
||||||
//printf("Line contaigns: %s" , buffer);
|
//printf("Line contaigns: %s" , buffer);
|
||||||
}
|
}
|
||||||
while(1){
|
while(1){
|
||||||
if(!fgets(buffer,sizeof buffer , stdin)) break;
|
if(!fgets(buffer,sizeof buffer , g)) break;
|
||||||
fprintf(f,"%s",buffer);
|
fprintf(f,"%s",buffer);
|
||||||
}
|
}
|
||||||
}
|
remove("rawData.txt"); rename("newFile.txt", "rawData.txt");
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,4 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void newFile(int nRow, FILE *f);
|
void clearRawData(int N);
|
||||||
void copyFile(FILE *f, FILE *g);
|
|
||||||
void replaceFile(int nRow, FILE *g);
|
|
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;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill(int** p, int N, int M) {
|
void fillRawData(int** p, int N, int M) {
|
||||||
int i, j;
|
int i, j;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
char *token;
|
char *token;
|
||||||
|
FILE *f = fopen("rawData.txt","r");
|
||||||
for(i = 0 ; i < N ; i++){
|
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);
|
//printf(buffer);
|
||||||
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
|
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
|
||||||
p[i][0] = atoi(token);
|
p[i][0] = atoi(token);
|
||||||
|
@ -48,13 +49,16 @@ void freeArray(int** p, int N) {
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc , char** argv){
|
int **getRawDataArray(){
|
||||||
int **p;
|
int **p;
|
||||||
p = get(nRow, nCol);
|
p = get(nRow, nCol);
|
||||||
fill(p ,nRow, nCol);
|
fillRawData(p ,nRow, nCol);
|
||||||
//print(p, nRow, nCol);
|
//print(p, nRow, nCol);
|
||||||
FILE *g = fopen(,"w"); //here to find the good one
|
clearRawData(nRow);
|
||||||
replaceFile(nRow,g);
|
//freeArray(p ,nRow);
|
||||||
freeArray(p ,nRow);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(int argc , char** argv){
|
||||||
|
getRawDataArray();
|
||||||
}
|
}
|
|
@ -3,4 +3,4 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.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 "power.h"
|
||||||
#include "getArray.h"
|
#include "getArray.h"
|
||||||
|
|
||||||
double power(int tab[nRow][8]){
|
double power(int **p){
|
||||||
double periode = 1 /freqEch;
|
double periode = 1 /freqEch;
|
||||||
double power[8];
|
double power[8];
|
||||||
for(int i = 0; i < 8; i++){
|
for(int i = 0; i < 8; i++){
|
||||||
int j = 0;
|
int j = 0;
|
||||||
double res = 0;
|
double res = 0;
|
||||||
while(1){
|
while(1){
|
||||||
if(!tab[j+1][i]) break;
|
if(!p[j+1][i]) break;
|
||||||
double aire = ( pow(tab[j][i],2) + pow(tab[j+1][i],2) ) / 2 * periode;
|
double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * periode;
|
||||||
res += aire;
|
res += aire;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ double power(int tab[nRow][8]){
|
||||||
return *power;
|
return *power;
|
||||||
}
|
}
|
||||||
int main(int argc , char** argv){
|
int main(int argc , char** argv){
|
||||||
FILE *f = fopen(argv[1],"r");
|
double pw = power(getArray());
|
||||||
double pw = power(getArray(nRow,f));
|
|
||||||
printf("%d" , pw);
|
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