Results 1 to 9 of 9

Thread:

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Monkey Business poseydon's Avatar
    Join Date: Mar:2004
    Location: Sofia
    Posts: 1,537

    . , . :

    #include <stdio.h>
    #include <stdlib.h>

    struct s {

    char fn[30];
    char ln[30];
    char u[30];
    char p[30];
    };

    struct s e;

    int main(void)
    {
    FILE *fp;
    char tmp[50];

    printf("Enter your first name\n");
    gets( e.fn );

    printf("Enter your last name\n");
    gets( e.ln);

    printf("Enter your username\n");
    gets( e.u);

    printf("Enter your password\n");
    gets( e.p);


    fp = fopen( "database.txt", "wb+" );
    if( fp != NULL ) {
    fwrite( &e, sizeof( struct s ), 1, fp );
    fclose( fp );
    }


    return 0;

    }


    , , . , , . , . if . overwrite- , "wb+" , "b+" , , , ... - , , , , , ...

    !
    Ad astra per aspera - To the stars through difficulties
    Nvidia - The way you are meant to be played!
    Blog - http://poseyd0n.blogspot.com/

  2. #2
    ! Rostislao's Avatar
    Join Date: Feb:2005
    Location: Bulgaria
    Posts: 822
    ... , ...

    :

    1)
    2)
    3)
    4)

    cout . ( cout) " : " ... cin ( ) - ... if(StringaDetoSiGoProchel=="1") {...} ... ( case). . getche()( ) 1 4 . . , ... -.
    " ? ..."

  3. #3
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    :
    Code:
    int answer;
    ...
    printf("1. Add account\n");
    printf("2. Search for account\n");
    printf("3. Exit\n\n?");
    scanf("%d", &answer);
    if (answer == 1) { .. /*  */ }
    else if (answer == 2) { /*  */ }
    else return 0;
    ...
    , 1) 2)

    1) ; , . add, append ("ab" , ).

    Code:
    .. // somewhere in the beginning:
    FILE *f;
    f = fopen("database.bin", "rb");
    if (!f) {f = fopen("database.bin", "wb");}
    fclose(f);
    ...
    ...
    ... // code for add operation:
    f = fopen("database.bin", "ab");
    fwrite(...)...
    ...
    2) : , , .

    , , :
    Code:
    FILE *f;
    f = fopen("database.bin", "rb");
    if (!f) {f = fopen("database.bin", "wb");}
    fclose(f);
    , ( ):
    Code:
    int file_size, n;
    ...
    f = fopen("database.bin", "rb");
    fseek(f, 0, SEEK_END);
    file_size = ftell(f);
    n = file_size / sizeof(s);
    , "n" . n+1 ( , add):

    Code:
    s *data;
    ...
    data = (s*) malloc((n+1)*sizeof(s));
    :
    Code:
    ...
    rewind(f);
    fread(data, sizeof(s), n, f);
    fclose(f);
    ...
    add, n, , :
    Code:
    f = fopen("database.txt", "wb");
    fwrite(data, sizeof(s), n, f);
    fclose(f);
    free(data);
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  4. #4
    ! Rostislao's Avatar
    Join Date: Feb:2005
    Location: Bulgaria
    Posts: 822
    ++
    " ? ..."

  5. #5
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    , Rostislao, ,
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  6. #6
    ! Rostislao's Avatar
    Join Date: Feb:2005
    Location: Bulgaria
    Posts: 822
    "" ++, . ( ) , .
    " ? ..."

  7. #7
    Monkey Business poseydon's Avatar
    Join Date: Mar:2004
    Location: Sofia
    Posts: 1,537
    ! , , ... ...
    Ad astra per aspera - To the stars through difficulties
    Nvidia - The way you are meant to be played!
    Blog - http://poseyd0n.blogspot.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |