You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
void del ( )
{
FILE * fp ;
int i , j , count = 0 ;
char ch [ 2 ] ;
char name [ 15 ] ;
if ( ( fp = fopen ( " data.txt " , " r+ " ) ) = = NULL )
{
printf ( " can not open \n " ) ;
return ;
}
while ( ! feof ( fp ) )
if ( fread ( & addrinfo [ count ] , LEN , 1 , fp ) = = 1 )
count + + ;
fclose ( fp ) ;
if ( count = = 0 )
{
printf ( " no record! \n " ) ;
return ;
}
display ( ) ;
printf ( " please input the name " ) ;
scanf ( " %s " , & name ) ;
for ( i = 0 ; i < count ; i + + )
{
if ( strcmp ( name , addrinfo [ i ] . name ) = = 0 )
{
printf ( " find the contact,del?(y \n ) " ) ;
scanf ( " %s " , ch ) ;
if ( strcmp ( ch , " Y " ) | | strcmp ( ch , " y " ) = = 0 )
for ( j = i ; j < count ; j + + ) //i为所需删的联系人, 需将i后的联系人都前移一个位置
addrinfo [ j ] = addrinfo [ j + 1 ] ;
count - - ;
if ( ( fp = fopen ( " data.txt " , " w " ) ) = = NULL )
{
printf ( " can not open " ) ;
return ;
} for ( j = 0 ; j < count ; j + + )
if ( fwrite ( & addrinfo [ j ] , LEN , 1 , fp ) ! = 1 )
{
printf ( " can not save! \n " ) ;
getch ( ) ;
}
fclose ( fp ) ;
printf ( " del successfully! \n " ) ;
return ;
}
}
printf ( " not find the contact " ) ;
}