主题:密码存储
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>
struct manage_data
{
long int manage_num;
char pin[6];
};
int main()
{
FILE* fp_manage;
char str[6] = {'\0'};
char ch;
int num;
struct manage_data* head;
head = (struct manage_data*)malloc(sizeof(struct manage_data));
if( head == NULL )
printf( "Insufficient memory available\n" );
else
{
printf( "Memory space allocated for path name\n" );
}
head->manage_num = 0;
fp_manage = fopen("f:/data.txt","w");
if(fp_manage == NULL)
{
printf("Open file error!");
}
printf("输入账号:");
scanf("%ld",&(head->manage_num));
getchar();
printf("输入密码:");
num = 0;
while( (ch=getch())!='\r' && num<6 )
{
if(ch =='\b'&&num>0)
{
num--;
putchar('\b');
putchar(' ');
putchar('\b');
}
else if(ch!='\b')
{
putchar('*');
str[num] =ch;
num++;
}
}
strcpy(head->pin,str);
fwrite(head,sizeof(struct manage_data),1,fp_manage);
free(head);
printf( "Memory freed\n" );
fclose(fp_manage);
return 0;
}
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>
struct manage_data
{
long int manage_num;
char pin[6];
};
int main()
{
FILE* fp_manage;
char str[6] = {'\0'};
char ch;
int num;
struct manage_data* head;
head = (struct manage_data*)malloc(sizeof(struct manage_data));
if( head == NULL )
printf( "Insufficient memory available\n" );
else
{
printf( "Memory space allocated for path name\n" );
}
head->manage_num = 0;
fp_manage = fopen("f:/data.txt","w");
if(fp_manage == NULL)
{
printf("Open file error!");
}
printf("输入账号:");
scanf("%ld",&(head->manage_num));
getchar();
printf("输入密码:");
num = 0;
while( (ch=getch())!='\r' && num<6 )
{
if(ch =='\b'&&num>0)
{
num--;
putchar('\b');
putchar(' ');
putchar('\b');
}
else if(ch!='\b')
{
putchar('*');
str[num] =ch;
num++;
}
}
strcpy(head->pin,str);
fwrite(head,sizeof(struct manage_data),1,fp_manage);
free(head);
printf( "Memory freed\n" );
fclose(fp_manage);
return 0;
}