Hi All,
I am a newbie in C programming. I was facing a problem with reading a text file and writing it as it is but i need to round some of the floating numbers to six decimal digits. I am posting my code as it is and example of how my text file looks like. As I am a beginner I need some suggestions and guide me into the right direction.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* data analysis for TI to sort out data by Integers, Floating Points,
Binary numbers, strings, fields */
main()
{
char ch, frst_100l[1024]; /* pointer ch character for file*/
FILE *fp; /* file pointer*/
printf("frst_100l"); /* name of the file */
gets(file_name);
fp = fopen("frst_100l","r+"); ");/*open the file name*/
/* if file is error , then excute error and exit failure */
if(fp == NULL)
{
printf("\n Error while openeing the file:frst_100l
");
exit (EXIT_FAILURE);
}
while( (Ch=getchar(fp))!=EOF) /* pointer ch to read the files
{
fputc(ch,fp);
if ( fp == '.')
{
fputc(ch,fp) if(fp==','of
fputc(ch,fp)
fputc(ch,fp)
fputc(ch,fp)
fputc(ch,fp)
fputc(ch,fp)
}
if( fp == ',')
{
fputc(ch,fp);
}
fclose(fp)
Example one line of the text file is below
04,-150,-75,-37,-18,-8,-4,6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,660.344421386719,,334.063598632813,
I also heard about atof function can anyone explain or educate me how that works....
Thanks,
Adoosa.