Results 1 to 9 of 9
Hybrid View
-
23rd March 2006 15:47 #1
. , . :
#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/
-
23rd March 2006 16:33 #2
... , ...
:
1)
2)
3)
4)
cout . ( cout) " : " ... cin ( ) - ... if(StringaDetoSiGoProchel=="1") {...} ... ( case). . getche()( ) 1 4 . . ,
... -.
" ? ..."
-
23rd March 2006 16:42 #3
:
, 1) 2)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) ; , . add, append ("ab" , ).
2) :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(...)... ...
, , .
, , :
, ( ):Code:FILE *f; f = fopen("database.bin", "rb"); if (!f) {f = fopen("database.bin", "wb");} fclose(f);
, "n" . n+1 ( , add):Code:int file_size, n; ... f = fopen("database.bin", "rb"); fseek(f, 0, SEEK_END); file_size = ftell(f); n = file_size / sizeof(s);
:Code:s *data; ... data = (s*) malloc((n+1)*sizeof(s));
add, n, , :Code:... rewind(f); fread(data, sizeof(s), n, f); fclose(f); ...
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
-
23rd March 2006 16:48 #4
-
23rd March 2006 17:02 #5
, Rostislao, ,
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
23rd March 2006 17:07 #6
-
23rd March 2006 18:09 #7
! , , ... ...
Ad astra per aspera - To the stars through difficulties
Nvidia - The way you are meant to be played!
Blog - http://poseyd0n.blogspot.com/




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in