Mada nije za scripting forum, evo ti Leko i u C-u isto to:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXREAD 4096
int main(int argc, char *argv[]) {
int nread, len = 0, size = (4 * MAXREAD);
char *cp, *offset, *buf = malloc(size + 1);
while (1) {
if ((nread = read(0, (buf + len), MAXREAD)) > 0) {
len += nread;
if (MAXREAD > (size - len)) {
size <<= 1;
if (0 == (buf = realloc(buf, size + 1))) {
fprintf(stderr, "realloc failed\n");
exit(1);
}
}
} else {
if ( 0 == nread) break;
if (-1 == nread) {
perror("read");
exit(1);
}
}
}
offset = buf + len;
*offset = 0;
for (cp = offset; cp > buf; --cp) {
if ('\n' == *cp) {
*offset = 0;
if (cp < offset)
fputs(offset = cp+1, stdout);
}
}
if (cp < offset) {
*offset = 0;
fputs(cp, stdout);
}
free(buf);
return(0);
}
Nije moj kod, naleteo sam na nekoj njuzgrupi na to..
Zatim pascal:
Code:
Program reversefile;
uses SysUtils, Classes;
var
i, N : longint;
list : TList;
line : string;
pline : pointer;
begin
list := TList.Create;
While Not Eof(input) do
begin
Readln(input, line);
Getmem(pline, Length(line)+1);
Move(line, pline^, Length(line)+1);
list.Add( pline );
end;
N := list.Count;
For i := N-1 Downto 0 do WriteLn( string(list.items[i]^) );
end.
Java:
Code:
import java.io.*;
import java.util.*;
public class reversefile {
public static void main(String[] args) {
ArrayList al = new ArrayList(4096);
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String strLine;
while((strLine = in.readLine()) != null)
al.add(strLine);
in.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
String strArray[] = new String[al.size()];
al.toArray(strArray);
for(int i = strArray.length - 1; i >= 0; i--)
System.out.println(strArray[i]);
}
}