T
Tad Johnson
Hi all,
I would not normally post about this issue but after a few hours of
struggling maybe it's time for some help. I am a pascal programmer moving to
C++. I am learning from a couple of books, one of which is Wrox Press's
"Beginners guide to C++". I am at a point where simple std.h header is being
used for text/bin string/char manipulation swo I figured I would try my luck
on a small edit project.
I am trying to take this string:
20040120,35.34000,36.29999,35.11999,36.21000,6172400
from the file AA.ASC, and change it to
AA,20040120,35.34,36.29,35.11,36.21,6172400
Structured changed to two digit prescision and begining of file name
appended
to beginning of line, within normal comma separated and lines perminated by
'\n'.
I am having major issues trying to figure out syntax for the frintf()
command. And
the books I am working with give very little clue to what I am doing wrong.
Should I used a character by charater approach outputting each character
into the write
file, or should I take it section by section with comma being separation
test in a do/while loop?
Any input?
#include <stdio.h>
int main ()
{
FILE * rFile;
FILE * wFile;
char string [100];
rFile = fopen ("AA.ASC","r"); //read file for input
if (rFile == NULL) perror ("Error opening file"); //no data for input,
stop
else {
fgets (string , 100 , rFile); //get string of max length of 100
}
wFile = fopen ("AA.txt", "w"); // create file AA.txt for output
if (!wFile) perror ("Error opening file"); //error if problem
else {
fprintf (wFile, "AA,%l, %f, %f",string); //output string formatted and
written
fclose (rFile); //close read file
fclose (wFile); //close write file
}
return 0;
}
Thanks much,
Tad
I would not normally post about this issue but after a few hours of
struggling maybe it's time for some help. I am a pascal programmer moving to
C++. I am learning from a couple of books, one of which is Wrox Press's
"Beginners guide to C++". I am at a point where simple std.h header is being
used for text/bin string/char manipulation swo I figured I would try my luck
on a small edit project.
I am trying to take this string:
20040120,35.34000,36.29999,35.11999,36.21000,6172400
from the file AA.ASC, and change it to
AA,20040120,35.34,36.29,35.11,36.21,6172400
Structured changed to two digit prescision and begining of file name
appended
to beginning of line, within normal comma separated and lines perminated by
'\n'.
I am having major issues trying to figure out syntax for the frintf()
command. And
the books I am working with give very little clue to what I am doing wrong.
Should I used a character by charater approach outputting each character
into the write
file, or should I take it section by section with comma being separation
test in a do/while loop?
Any input?
#include <stdio.h>
int main ()
{
FILE * rFile;
FILE * wFile;
char string [100];
rFile = fopen ("AA.ASC","r"); //read file for input
if (rFile == NULL) perror ("Error opening file"); //no data for input,
stop
else {
fgets (string , 100 , rFile); //get string of max length of 100
}
wFile = fopen ("AA.txt", "w"); // create file AA.txt for output
if (!wFile) perror ("Error opening file"); //error if problem
else {
fprintf (wFile, "AA,%l, %f, %f",string); //output string formatted and
written
fclose (rFile); //close read file
fclose (wFile); //close write file
}
return 0;
}
Thanks much,
Tad