Stack Overflow challenge!
1
Name:
Anonymous
2010-08-21 20:20
1. Create a new text file called "fileio.txt"
2. Write the first line "hello" to the text file.
3. Append the second line "world" to the text file.
4. Read the second line "world" into an input string.
5. Print the input string to the console.
2
Name:
Anonymous
2010-08-21 20:23
3
Name:
Anonymous
2010-08-21 20:27
4
Name:
Anonymous
2010-08-21 21:15
test
test
5
Name:
Anonymous
2010-08-21 21:16
I upgoated .
6
Name:
Anonymous
2010-08-21 22:56
>>1
What is the purpose of this challenge?
7
Name:
Anonymous
2010-08-22 0:05
>>6
To flustrate toy languages users which don't have intuitive fileio(U MENA HASKELL)?
8
Name:
Anonymous
2010-08-22 1:31
>>1
#!/bin/sh
touch fileio.txt
echo hello > fileio.txt
echo world >> fileio.txt
X=`head -n 2 fileio.txt | tail -n 1`
echo $X
9
Name:
Anonymous
2010-08-22 1:57
>>7
Maybe this is totally kludgy; I'm a newbie Haskell programmer. Anyway...
import System.IO
main :: IO ()
main = do
soc <- openFile "fileio.txt" ReadWriteMode
hPutStrLn soc "Hello"
pos <- hTell soc
hPutStrLn soc "World"
hSeek soc AbsoluteSeek pos
inpStr <- hGetLine soc
hClose soc
putStrLn inpStr
10
Name:
Anonymous
2010-08-22 5:00
>>9
Needs less
do and more
>>=s.
11
Name:
Anonymous
2010-08-22 7:50
12
Name:
Anonymous
2010-08-22 9:39
13
Name:
Anonymous
2010-08-22 10:44
var fs = require("fs");
var sys = require("sys");
var path = "fileio.txt";
fs.writeFile(path, "hello", function (error) {
fs.open(path, "a", 0666, function (error, file) {
fs.write(file, "\nworld", null, "utf-8", function () {
fs.close(file, function (error) {
fs.readFile(path, "utf-8", function (error, data) {
var lines = data.split("\n");
sys.puts(lines[1]);
});
});
});
});
});
14
Name:
Anonymous
2010-08-22 11:29
>>13
I'll never understand how the Node.js people managed to convince programmers to manually write code in CPS
15
Name:
Anonymous
2010-08-22 12:25
16
Name:
Anonymous
2010-08-22 12:38
CopyFile("input.txt","output.txt")
17
Name:
Anonymous
2010-08-22 12:50
18
Name:
Anonymous
2010-08-22 12:50
#include "void.h"
#define COPYBLOCKSIZE 65535
mainstart;//Optimized, fast file copy
FILE*in=fopen(argv[1],"rb");
FILE*out=fopen(argv[2],"wb");
char inbuf[COPYBLOCKSIZE];char incache[COPYBLOCKSIZE];
char outbuf[COPYBLOCKSIZE];
setvbuf(in,inbuf,_IOFBF,COPYBLOCKSIZE);
setvbuf(out,outbuf,_IOFBF,COPYBLOCKSIZE);
size_t blockrlim;size_t blockwcheck;
while(!feof(in)){
blockrlim=fread(incache,1,COPYBLOCKSIZE,in);
blockwcheck=fwrite(incache,1, blockrlim, out);
}
if (ferror (in)||ferror(out)){perror("File copy error");}
if ( filelength(fileno(in))!= filelength(fileno(out))){puts("File copy size mismatch");}
fclose(in);
fclose(out);
mainend;
19
Name:
Anonymous
2010-08-22 13:19
#include "void.h"
#define CACHESIZEDEF 1048576
mainstart;//Optimized
if(!argv[1]){puts("Syntax:EnterpriseFileCopyUtility file1 file2 [cachesize]");goto endcopy;}
size_t blockrlim,blockwcheck;
long cblocksize=argv[3]?(atol(argv[3])?atol(argv[3]):CACHESIZEDEF):CACHESIZEDEF;
FILE*in=fopen(argv[1],"rb");
FILE*out=fopen(argv[2],"wb");
if(!out||!in){perror("Cannot open");}
char* inbuf=malloc(cblocksize);
char* outbuf=malloc(cblocksize);
char* incache=malloc(cblocksize);
setvbuf(in,inbuf,_IOFBF,cblocksize);
setvbuf(out,outbuf,_IOFBF,cblocksize);
while(!feof(in)){
blockrlim=fread(incache,1,cblocksize,in);
blockwcheck=fwrite(incache,1, blockrlim, out);
if(blockwcheck!=blockrlim){puts("Block copy size mismatch");break;}}
if (ferror (in)||ferror(out)){perror("File copy error");}
fclose(in);fclose(out);free( inbuf);free( outbuf);free(incache);
endcopy:;mainend;
20
Name:
Anonymous
2010-08-22 14:09
#include "stackoverflowfileiochallenge.h"
DOCHALLENGE;
21
Name:
Anonymous
2010-08-22 14:34
#include "void.h"
#define CACHESIZEDEF 1048576
mainstart;//Optimized
if(!argv[1]){puts("Syntax:EnterpriseFileCopyUtility file1 file2 [cachesize] [s|silent]");goto endcopy;}
size_t blockrlim,blockwcheck;
long cblocksize=argv[3]?(atol(argv[3])?atol(argv[3]):CACHESIZEDEF):CACHESIZEDEF;
FILE*in=fopen(argv[1],"rb");
if(!in){perror("Cannot open");goto endcopy;}
FILE*out=fopen(argv[2],"wb");
if(!out){perror("Cannot open");goto endcopy;}
char* inbuf=malloc(cblocksize);
char* outbuf=malloc(cblocksize);
char* incache=malloc(cblocksize);
setvbuf(in,inbuf,_IOFBF,cblocksize);
setvbuf(out,outbuf,_IOFBF,cblocksize);
while(!feof(in)){
blockrlim=fread(incache,1,cblocksize,in);
blockwcheck=fwrite(incache,1, blockrlim, out);
if(blockwcheck!=blockrlim){puts("Block copy size mismatch");break;}}
if (ferror (in)||ferror(out)){perror("File copy error");}
fclose(in);fclose(out);free( inbuf);free( outbuf);free(incache);
endcopy:;mainend;
22
Name:
Anonymous
2011-01-31 20:55
<-- check em dubz
23
Name:
Anonymous
2011-02-03 8:29