A
allpervasive
hi all, this is reddy, a beginner to c lang,,here i have some problems
in reading and modifying the contents of a file,, hope you can help to
solve this problem. Here i attach the file to be modified and the
program code.
In the attached file below i just want to change the value of
data(only float value) after the line 1 P V T 1 15 till 2 G TT,
from positive to negative and vice versa, and wire the date in other
file. can someone help me to solve this.
thanks.
*** MEAS(T,L) DATA ***
/07/07
T
8
PINION
3
2
2
119.6329
-113.2538
74.8409
2.0000
1 P V T 1 15
20 -6.2
21 -4.0
22 0.7
1 P V L 1 5
23 3.9
24 -5.1
25 5.2
26 -5.7
1 P V T 3 15
27 5.9
28 -5.2
2 G TT
1 1.2488
3 1.2598
END
program code:
do {
if (c=fgets(file1, sizeof file1, in1) !='\n'
&& sscanf(file1,"%d %f",&num,&value) == 2)
{
value= (value- (2*value));
printf("%d %1.1f\n", num, value);
fprintf(append3,"%d %1.1f\n", num, value);
}
else
{
for(j=0;;j++){
printf("%c",file1[j]);
fprintf(file2,"%c",file1[j]);
if(file1[j]=='\n')break;}
}
} while (!feof(in1));
return EXIT_SUCCESS;
in reading and modifying the contents of a file,, hope you can help to
solve this problem. Here i attach the file to be modified and the
program code.
In the attached file below i just want to change the value of
data(only float value) after the line 1 P V T 1 15 till 2 G TT,
from positive to negative and vice versa, and wire the date in other
file. can someone help me to solve this.
thanks.
*** MEAS(T,L) DATA ***
/07/07
T
8
PINION
3
2
2
119.6329
-113.2538
74.8409
2.0000
1 P V T 1 15
20 -6.2
21 -4.0
22 0.7
1 P V L 1 5
23 3.9
24 -5.1
25 5.2
26 -5.7
1 P V T 3 15
27 5.9
28 -5.2
2 G TT
1 1.2488
3 1.2598
END
program code:
do {
if (c=fgets(file1, sizeof file1, in1) !='\n'
&& sscanf(file1,"%d %f",&num,&value) == 2)
{
value= (value- (2*value));
printf("%d %1.1f\n", num, value);
fprintf(append3,"%d %1.1f\n", num, value);
}
else
{
for(j=0;;j++){
printf("%c",file1[j]);
fprintf(file2,"%c",file1[j]);
if(file1[j]=='\n')break;}
}
} while (!feof(in1));
return EXIT_SUCCESS;