1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| void readfromfile(char*name){
int i,length,t,filesize;
FILE *fic;
char command[256];
char *chaine;
fic = fopen(name,"r");
if(fic==NULL)
{
<div style="margin-left:40px"> printf("Can not open the file %s\n",name);</div>}
fseek(fic,0,SEEK_END);
length=ftell(fic);
fseek(fic,0,SEEK_SET);
chaine=(char*)malloc(length*sizeof(char));
fread(chaine,length,1,fic);
fclose(fic);
i=0;
t=0;
//command=(char*)malloc(length*sizeof(char));
filesize=0;
for (i=0;i<length;i++){
<div style="margin-left:40px"> if (chaine[i]=='\n') filesize++;</div>}
printf("%d \n",filesize);
fic = fopen(name,"r");
for(t=0;t<filesize;t++){
fgets(command,length,fic);
printf("%s \n",command);
}
fclose(fic);
} |
Partager