ok, I have a very serious somewhat simple problem that I just can't seem to figure out myself. Simply put I want to make a program take the lines
Hello
How
Are You
ToDay
and output
ToDay
Are You
How
Hello
Using the End of data marker as a newline character.
The size of the data inbetween newline characters can be any size from 1 000 000 to 5 characters.
So far this is what I got
FILE * in = fopen("input.txt","r");
int newlcount = 0;
int total = 0;
char ch;
for(ch = '\n';ch != EOF;total++)
{
ch = fgetc(in);
if (ch == '\n')
newlcount++;
}
rewind(in);
total = newlcount;
FILE*out = fopen("flipped lines.txt","w");
for(int num = 0,count = 0;num < total;num++)
{
while ((total - num) != count)
{
ch = fgetc(in);
if (ch == '\n')
{
count++;
}
}
count = 0;
ch = 'x';
while (ch != '\n'&&ch!= EOF)
{
ch = fgetc(in);
printf("%c",ch);
}
rewind(in);
}
people might argue that this works, but it doesn't. I would like this program to be solved by any means necessary as long as its in C/C++.