this is a code wich is supposed to take all numbers with 2 decimals in Balun.txt and is supposed to divde them by 10000 and then modify them so that they have only 2 decimals and write them back.
can anyone please help me with this.
i'm trying for 2 hours and i can't get it right.
Code:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
FILE *f=fopen("Balun.txt","r+");
char ch[4000];
ch[0]=0;
while(!feof(f))
{
fscanf(f,"%s",&ch);
if(strstr(ch,".00")!=NULL)
{
int lungime=strlen(ch);
int lungimenou;
double cifra=atof(ch);
cifra/=10000;
sprintf(ch,"%f",cifra);
ch[strlen(ch)-4]=NULL;
lungimenou=strlen(ch);
for(int i=lungimenou;i<=lungime;i++)
ch[i]=' ';
fseek(f,SEEK_CUR,-lungime);
ch[lungime]=NULL;
fwrite(ch,lungime-1,1,f);
if (ferror (f))
printf ("error!!!\n");
printf("%s\n",ch);
//getch();
}
else printf("string\n");
};
system("pause");
fclose(f);
return 0;}