Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Stack Overflow challenge!

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.

Name: Anonymous 2010-08-21 20:23

>>1
Less of this.

Name: Anonymous 2010-08-21 20:27

>>2
Less of this.

Name: Anonymous 2010-08-21 21:15

test
test

Name: Anonymous 2010-08-21 21:16

I upgoated.

Name: Anonymous 2010-08-21 22:56

>>1
What is the purpose of this challenge?

Name: Anonymous 2010-08-22 0:05

>>6
To flustrate toy languages users which don't have intuitive fileio(U MENA HASKELL)?

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

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

Name: Anonymous 2010-08-22 5:00

>>9
Needs less do and more >>=s.

Name: Anonymous 2010-08-22 7:50

Name: Anonymous 2010-08-22 9:39

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]);
                });
            });
        });
    });
});

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

Name: Anonymous 2010-08-22 12:25

>>14
Where is my >>=?

Name: Anonymous 2010-08-22 12:38

CopyFile("input.txt","output.txt")

Name: Anonymous 2010-08-22 12:50

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;

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;

Name: Anonymous 2010-08-22 14:09

#include "stackoverflowfileiochallenge.h"
DOCHALLENGE;

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;

Name: Anonymous 2011-01-31 20:55

<-- check em dubz

Name: Anonymous 2011-02-03 8:29

Name: Anonymous 2013-08-31 23:32



   \            、____        /      /
     \          _ゝ、7´i-‐''7´ /    /
            ,.. -‐ ''"´ ̄  `"''ー' 、_     /
\       ,. '":::::::::::::::::::::::::::::::::::::::::::::`ヽ         /
  \       i::::::::ゝ:::_;:ゝ=== - 、、ィ:::::::::::::',       /
         / ''"´           `''、ヽ:::!   
\____)、____//´/  / ハ  i  ハ   i   ヽY \        /
        i / !  >'、/,_,| / | /_,!イ ハ ! |    ヽ、__人___,/(_
 ク.  こ   |' | /ヽ !__ レ' レ' ,.!-‐-、。oヽ!|    /i
 ソ.  の  ! ./レ'o '"´ ` ,     、、,,! !--─ァ ノ | 効 攻 あ
 チ  ク  \__.ハ""   ,. -‐‐ 、   ハ!-‐'i" r'_,.イ| か 撃 ん
 ン   .ソ  「 ___!,ヘ    i´     ',  / |_!_,ハノン_,,../ な .な .た
 チ  チ  |' !  i7>.、.,ヽ.    ノ,.イ| イ'´   `ヾ´./  い ん .ら
 ン  ン   | i,ヘ,.!-- 、ヘ`=r-=i´、::ヽ!/      Y`ヽ  の か の
 ! !  チ   |/    `ヽ、 \./ !::::ヽ_     'r____,i. よ
    ン   !       i::\}>o<{:::ヽ、__,,..-'" r-ノ  ! !
    ! !   ,>     /::::::::::::/::::::::::::::Y   _,ゝ'ヽ.  __
⌒y^ヽ.  ,へ(〉、,.-r-、ゝイ:::::::::/:::::::::i::::::::iVヽヘ「   )'´ `Y´`ヽ.
/   \!  /`     'ハ/::}>o<{:::::::::::l::::::::!     \
      ./     /ヘ:::::::/:::::::::::::::::::::::イゝ、_     \

Name: Anonymous 2013-09-01 1:04



                _,,.. -─- 、..,,_              ,. -─-
          ,. -‐-<´        `'ro、        /
        /      `          ゝ-、`o、     ;'   あ あ
       /    ;      /        ` 、ソ `:,    !   .な  :
      ;'   /   ;'   !     !   ',   ';   !    |    を  :
      i   i   /;-‐‐ナ!  ;'  ,ハ‐- 、 !   !  ;'!   |   か. :
      '、   '、 ./,!'--、/| //iァ--'、 |  / / .i   !   し
       \.  `y' ;'´ハ レ'   ;'´ハ Y「二i/ ,'  ∠.   ?
        /へ./! ,!__り ..::::::... !__り ! !  |   /    `''ー------‐
        ,'  ;.'´)///    '   ///(`iこ_,!  ';
      /   | '!,      ;'´ ̄ヽ.   ,ノ ',   ';.  ! 。
      ;'    !   `ヽ.  !_   _j ,.'´  i'ノ´ ) ,ハ  o     、l | ll l || l l|
      !.   _'、   .ノ> 、.,,___,,. イ!  r'´ _ノ!ソ`(   ○ ヽ`
     ノヽ  /rソ  /!'´>'i     ,!ヘ ./ ̄  ノ)     .三   穴
    ( ソ/,'::!   /!|'"´! \,ニ,/ |7,. '"´,.イ`i\    Ξ   犯
     )/  .i::::'、 /::!|、 |・ /|ヽ ・;'__,, -''´ノ) !::::';ヽ.   ニ   し
     ;'   '、::::ヾ、_;リ::';. レ' |:::::| \.!  / ;'//:::::! ',  三   !?
     /!    \:::::V:!:::!   |:::::|   '、 /o o'!/::::::/  ト、 彡,
    ;' !     ';:::::::ハ:|、   |::::::!   V、_____ノ':::/   ! i   '/l | ll | ll |l |l

Name: Anonymous 2013-09-01 2:35



                / /<___/`ー'´::::::::::::!  \__>-、_ \
               ///:;ハ:::::::::::::::::::::::::::::::    /\_| \ \
              _r|./::/!:::ト、:::::::::::::::::            |   \ ':,
   ト.、         |_/:::/:::::|:::|::::::        :  /     \__,ハ ',
   |::::|`ー‐--、   _//‐‐-/::/__.   \     i /          `| ハ
   ∨ヽ、 ̄\:::Y´/:/    /::/  `' 、  \   /〉'             |  |
    \::`<´|:/´_]く__r‐-'-‐ァ─-、   \   //--  ─       ̄\_!
     /\_,>r'´   _」-─-'、_  \   '、.//              〈_,|
   _ノ´ ̄   ,>‐ '"´        \_/ ̄i___//              / イ
  く__/ ̄ ,>'´     ,  i      ヽ. \__.//|〉              / /
  / \,./   i    /|  ,ハ-‐-八    ',   //へ、          / /
  └-、/7     !-‐ァ' |/ァ'〒テァt\   | //ハ‐、/__   __,,.. -‐''"´i/
    └|  `ヽ| ァ'=‐     ゝ-‐'´ | \.|//  |‐'_r、  ̄  ,|_r‐'´
     `ヽ.  ,ハ ,.  ,     "/|/ //   ,ハ、  ` ̄ ̄
       )イ /|    _ _,.  / / .//   /   \
  ト、    /.レ' .ト 、,       / / >//-‐-'、   ,!  \
 /::::|  /  /  | /|`>/7 ̄`ーく7://::::::::::::::`Y .|   ',\
く:::::_|7´ _/!  |'_」/ァ//    /:://:::::::::::::::::::::∨    ! ハ
 >'´ヽ,イ::`7| ./::::/| //  /|:::://!::::::::::::::::::::::::|   | /  i
ノ`Y´\::/ |/:::::::/ ,// /ノ´`ヽ/ |::::::::::::/::::::::::〉 ./| ノ⌒7
  /   /  /::::ァ'´二`''く/(i/´   ∨r‐、_/::::::::;:イ//|く::::::く
 ,| /  r〈:::::/  -‐ノ`ー':〈_r-、   |/´ ̄`ヽこン'./ .| \_j、
/ レ'   r〉ー/   ン'〈/:::|__/ /、   \    /イ /   ,ハ 〈  \
 ,|    i7/   /::::::::::/ / /:::ヘ   \ /| |/ / ,| ノ    )

Don't change these.
Name: Email:
Entire Thread Thread List