Write zeros in ansi c

This is a discussion on Write zeros in ansi c within the C Programming forums, part of the General Programming Boards category; hi i am looking for an ANSI C program to write Zeros to a floppy disk any source code available ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    Write zeros in ansi c

    hi i am looking for an ANSI C program to write Zeros to a floppy disk any source code available ?
    thanks,
    ed.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Code:
    #include <stdlib.h>
    
    int main(void)
    {
      system("echo 000000000 > /dev/floppy);
      return 0;
    }
    If that's not what you want, then you need to give more information on what exactly you're trying to do.
    If you understand what you're doing, you're not learning anything.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    fputc( 0, fp );
    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    2
    hi thanks for your reply, i am trying to write zeros to a floppy disk in DOS.
    a 1.44mb disk
    thanks, ed.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    quzah's suggestion will work just fine then.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Trying to format the diskette, by any chance?
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    I don't see a bunch of 0s as much of a format...
    If you understand what you're doing, you're not learning anything.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Well... I mean, what else would you want to write zeroes to a disk for...?
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Formatting is setting up the disk for use with a given file system. Zero-filling is to effectively wipe what's been there before. Google 'undelete' if you still need help understanding the why.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    ahhh... you're filling the diskette with zero's so as to effectively replace the data that was stored there before???
    but doesnt a FULL FORMAT erase everything on a disk?

  11. #11
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Who knows what he's doing? He didn't give a lot of information in his question which is why I gave him an equally half-assed answer.
    If you understand what you're doing, you're not learning anything.

  12. #12
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Ya gotta love these people with their vague questions, who when propositioned
    for a more specific question, regurgitate their original question with a few words
    changed!

    I'm assuming the same as quzah, that you want to "wipe" the disk. A full format
    is the best way to do this, because if you were to directly write 0 to each sector
    on the disk, it would probably have to be formatted to be used again.

    If I'm not mistaken, floppy disks use FAT file system (at least under windows -
    not sure, but if I'm wrong, someone will undoubtedly correct me). That'll
    undoubtedly take a few bytes, regardless of file system. Find out the maximum
    size file you can it on the formatted disk, write a program that generates a
    text file of that size (filled with 0's if you like), and copy it to the disk!

    If you really want to destroy your evidence, I suggest throwing the floppy in a
    fire: magnetic tape + heat = no data
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  13. #13
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    That's called degaussing, and writing zeroes to format a disk isn't a very good idea to me. I prefer AES to start with, and something called a shredder to end with. But heck, if the OP isn't talking, we'll do good to leave it at that.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  14. #14
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    will copying sumthin big like a file which is 1.3megs large work too?? i mean, it may not totally fill up the disk, but at least most of it will be overwritten right? the remaining bits will be unreadable (hopefully)

    what've u got in that floppy anyways??

  15. #15
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Quote Originally Posted by deus
    hi i am looking for an ANSI C program to write Zeros to a floppy disk any source code available ?
    thanks,
    ed.
    Here's a nice ANSI C program in action:

    Code:
    dd if=/dev/zero of=/dev/fd0
    And the source code's even available too!


    /dev/urandom would probably do a better job of scrambling the disk.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make itoa write the left zeros?
    By pajaro in forum C Programming
    Replies: 5
    Last Post: 03-10-2009, 01:48 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 03:00 AM
  3. Write in many command prompts
    By cfriend in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2004, 02:32 AM
  4. Some humour...
    By Stan100 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-06-2003, 10:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21