回分類題庫
d214: CP2 Lab Exercise: Touch the Buttom Line of IO
出處:

Difficulity : N/A
Accepted : 48 Times | Submit :112 Times | Clicks : 1528
Accepted : 46 Users | Submit : 46 Users | Accepted rate : 100%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2011-03-02 15:19

Content :

Time to know what's going on under there!
"The night is darkest just before the dawn. And I promise you, the dawn is coming."

You are asked to write a simple fscanf and fprintf : myfscanf and myfprintf , using fread and fwrite. To simplify problem, you only need to deal with input / output one variable.

int myfprintf(FILE *stream, const char* format, void* arg)
    Similar to fprintf, except the last argument arg is the variable you need to output.
        format can be:
            %s => output arg as a string
            %d => output arg as an integer
            %hd => output arg as a short integer
            %c => output arg as a char
            %f => output arg as a double
        stream: the destination to output.
 

int myfscanf(FILE *stream, const char* format, void* arg)
    Similar to fscanf, except the last argument arg is the variable you need to input.
        format can be:
            %s => input a string to arg
            %d => input an integer to arg
            %hd => input a short integer to arg
            %c => input a char to arg
            %f => input a double to arg
        stream: the source of input.
 

Return value:
Both myfprintf and myfscanf shall return how many bytes they write / read.
Copy the source code and implement the two function and submit, no sample input/output.

What you can't do:
Use: fscanf, fprintf, scanf, printf
Modify the main function
Cheating, of course.

Input :

Nope

Output :

Nope

Sample Input :

10000000
20000000
32767
3.14159
g w
ThisIsABookOfEliILoveLOTRHarryPotterIsWierdThisIsABookOfEliILoveLOTRHarryPotterIsWierd
-20000000
-10000000
-32766
-3.14159
C S
HJUJILHGlkglsfgk;)(&ksgh;slghosgs;gsdg08)(OAHFjlDfpgj-g9-usg249uskjgpgnlsdg90sujskdgp0dg0sd

Sample Output :

Testing myfscanf and myfprintf:
%%d:
By printf: 10000000 20000000
10000000 20000000
%%hd:
By printf: 32767
32767
%%f:
By printf: 3.141590
3.141590
%%c:
By printf: g w
g w
%%s:
By printf: ThisIsABookOfEliILoveLOTRHarryPotterIsWierdThisIsABookOfEliILoveLOTRHarryPotterIsWierd
ThisIsABookOfEliILoveLOTRHarryPotterIsWierdThisIsABookOfEliILoveLOTRHarryPotterIsWierd
%%d:
By printf: -20000000 -10000000
-20000000 -10000000
%%hd:
By printf: -32766
-32766
%%f:
By printf: -3.141590
-3.141590
%%c:
By printf: C S
C S
%%s:
By printf: HJUJILHGlkglsfgk;)(&ksgh;slghosgs;gsdg08)(OAHFjlDfpgj-g9-usg249uskjgpgnlsdg90sujskdgp0dg0sd
HJUJILHGlkglsfgk;)(&ksgh;slghosgs;gsdg08)(OAHFjlDfpgj-g9-usg249uskjgpgnlsdg90sujskdgp0dg0sd
End of test.

Hint :


  

Author :


  Solve it!   Status Forum (0)

C++
C
JAVA
30307. cp98703024 (8 ms , 262KB)
30306. cp99703006 (2 ms , 262KB)
30305. hubuki (2 ms , 270KB)
30300. cp99703040 (2 ms , 268KB)
30291. cp99703039 (2 ms , 266KB)
30286. cp99703001 (2 ms , 262KB)
沒有解題記錄

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡