something like this maybe?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BUFF 1024
int main (int argc, const char **argv)
{
char backwords[MAX_BUFF];
FILE *fp;
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "File not found\n");
exit(1);
}
int c ,len,cnt = 0;
//put into array
while ( (c = fgetc(fp) ) != EOF)
{
backwords[cnt++] = c;
}
len = strlen(backwords);
//this code prints everything backwards
// bottom to top
for (; len>=0;len--)
{
if(backwords[len] == 10)
printf("\n");
else
printf("%c",backwords[len]);
}
printf("\n\n\n");
char line[1024];
// prints each line backwards top to bottom
//
len = strlen(backwords);
cnt = 0; //reset
for( int a =0;a<len;a++)
{ //use cnt to add amount
line[cnt++] = backwords[a];
if (backwords[a] == 10)
{
for (; cnt>=0;cnt--) //resets cnt to zero at the same time
{
printf("%c",line[cnt-1]);
}
// printf("\n");
}
}
//may be needing to zero out the line array for block out over run
// of last line put into that array. for safety measures.
fclose(fp);
return 0;
}
test file and output
Code:
One more thing, is there a need to free() the memory allocated?
And if so do i insert it in the while cicle or at the end of the code?
Thank you very much!
?detacolla yromem eht )(eerf ot deen a ereht si ,gniht erom enO
?edoc eht fo dne eht ta ro elcic elihw eht ni ti tresni i od os fi dnA
!hcum yrev uoy knahT
still needs clean up code and windows end line and whatever else you deem necessary
K.I.S.S.