📄 main.c
字号:
#include <string.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>#include <signal.h>#include <string.h>#include <ctype.h>#include <sys/types.h>#include <assert.h>/*************************************************************************//* *//* Save file *//* *//*************************************************************************/void SaveProj(long int *Data,int nb_bins,char nom[256]){ FILE *fptr=NULL; int a,i; long int buf_val2; printf("sauvegarde dans %s\n",nom); if ((fptr = fopen(nom,"w")) == NULL) { printf("Impossible de creer le fichier %s\n",nom);exit(1); } for (i=0;i<nb_bins+1;i++) if (i==0) fprintf(fptr,"%d\n",nb_bins); else { buf_val2 = Data[i-1]; a = fprintf(fptr,"%ld\n",buf_val2); if (a<0) printf("PROBLEME\n"); } fclose(fptr);}/*******************************************************************//* *//* main *//* *//*******************************************************************/int main (int argc, const char * argv[]) { FILE *fptr; char nom_proj[256], nomRLE[256]; int i; int k,l,Count; int nb_bins; long int a; long int *InputProj; long int *RLEProj; sprintf(nom_proj,"%s",argv[1]); if (!strcmp(argv[1],"-h")) { printf("\n\n./RLE <Projection.txt>\n\n"); exit(0); } printf("\nouverture de %s .....",nom_proj); if ((fptr = fopen(nom_proj,"r")) == NULL) { printf("Impossible d'ouvrir le fichier %s\n",nom_proj);exit(1);} fscanf(fptr,"%d\n",&nb_bins); printf("OK\t"); printf("Nb de bins : %d \n",nb_bins); InputProj = (long int *) calloc (2*nb_bins,sizeof(long int)); RLEProj = (long int *) calloc (2*nb_bins,sizeof(long int)); for (i=0;i<nb_bins;i++) { a = fscanf(fptr,"%ld\n",&InputProj[i]); if (a<0) { printf("PROBLEME 1\n"); exit(1); } } fclose(fptr); k=0;l=0;Count=0; for (i=0;i<2*nb_bins;i++) { do { k++; Count++; } while (InputProj[i] == InputProj[i+k]); RLEProj[l] = k; k=0; RLEProj[l+1] = InputProj[i]; i=Count; l+=2; } sprintf(nomRLE,"%sRLE.txt",nom_proj); SaveProj(RLEProj,2*nb_bins,nomRLE); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -