I have a script to read a file that has text on lines. The script is supposed to take the text and make them into space delimited and save the new text to a new file. I am able to only accomplish this with 1 line from the text file. I am new to c++, and have been using Herbert Schildt's C++ book. My other problem I am trying to solve is that the file I am using I wont know how many lines of text I will be converting. I have tried different loops none seem to work. here is a sample of what I've written if any one has any ideals, I would really appreciate the assistance. This is not a test for class or anything:
int main(void)
{
FILE *data;
FILE *TestFile;
// FILE *dataholder;
int i;
int j;
int k;
int x = 0;
char ch;
char str[4], str2[6], str3[6], str4[6];
if((data=fopen("file.txt", "r")) == NULL) {
printf("cannot open file.\n");
}
if((TestFile=fopen("testing.txt", "w")) ==NULL) {
printf("cannot open file.\n");
}
{
fscanf(data, "%[DAT]%[C]%d%[T]%d%[F]%d" , str, str2, &i, str3, &j, str4, &k);
cout << str<<" "<< str2<<i<<" "<< str3<<j<<" "<< str4<<k;
}
fclose(data);
fclose(TestFile);
return 0;
}