please explain this lines of code
-
Dear friends, I don't understand the below codes, please explain for me:
case 3:
{
system("cls");
do
{
found = 0;
printf("\n\n\t..Contact Search\n\t=================================\n\t...Name of Contact to search: ");
fflush(stdin);
scanf("%[^\n]",&querry);
l=strlen(querry);
fp=fopen("Contact.dll","r");
system("cls");
printf("\n\n::Search result for: 's'\n====================================\n", querry);
while(fread(&list,sizeof(list),1,fp)==1)
{
for(i=0;i<=l;i++)
{
name[i]=list.name[i];
name[1]='\0';
}
}
if (stricmp(name,querry)==0)
{
printf("\n..::Name\t: %s\n..::Phone\t: %ld\n....::Address\t %s\n.....::Email\t:%s\n", list.name,list.ph,list.add,list.email);
found++;
if(found%4==0)
{
printf("Press any key to continue..");
getch();
}
}
if(found==0)
{
printf("\n..:No match found");
}
else
{
printf("\n....match(s) found!",found);
}https://www.codeproject.com/script/Forums/Edit.aspx?fid=3785&floc=/Forums/3785/Managed-Cplusplus-CLI.aspx#
fclose(fp);
printf("\n.......Try again ? \n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
}while (ch==1); } break;
---------------------------------------------- while(fread....) --> what does this mean ?
if (stricmp(name,q
.... --> what does it mean ? Please explain for me , thank you very much! Hieu
-
Dear friends, I don't understand the below codes, please explain for me:
case 3:
{
system("cls");
do
{
found = 0;
printf("\n\n\t..Contact Search\n\t=================================\n\t...Name of Contact to search: ");
fflush(stdin);
scanf("%[^\n]",&querry);
l=strlen(querry);
fp=fopen("Contact.dll","r");
system("cls");
printf("\n\n::Search result for: 's'\n====================================\n", querry);
while(fread(&list,sizeof(list),1,fp)==1)
{
for(i=0;i<=l;i++)
{
name[i]=list.name[i];
name[1]='\0';
}
}
if (stricmp(name,querry)==0)
{
printf("\n..::Name\t: %s\n..::Phone\t: %ld\n....::Address\t %s\n.....::Email\t:%s\n", list.name,list.ph,list.add,list.email);
found++;
if(found%4==0)
{
printf("Press any key to continue..");
getch();
}
}
if(found==0)
{
printf("\n..:No match found");
}
else
{
printf("\n....match(s) found!",found);
}https://www.codeproject.com/script/Forums/Edit.aspx?fid=3785&floc=/Forums/3785/Managed-Cplusplus-CLI.aspx#
fclose(fp);
printf("\n.......Try again ? \n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
}while (ch==1); } break;
---------------------------------------------- while(fread....) --> what does this mean ?
if (stricmp(name,q
.... --> what does it mean ? Please explain for me , thank you very much! Hieu
Hiếu Ngô wrote:
while(fread....) --> what does this mean ?
It means repeat the loop while that condition remains true. So if the
fread
function returns any value other than 1 the loop will terminate.Hiếu Ngô wrote:
if (stricmp(name,q. --> what does it mean ?
It means compare two strings ignoring the case of characters. So "AbCd" will match "aBcD" or "abcd" etc. Full details of these, and other functions, constructs etc., are in the language references on MSDN.
-
Dear friends, I don't understand the below codes, please explain for me:
case 3:
{
system("cls");
do
{
found = 0;
printf("\n\n\t..Contact Search\n\t=================================\n\t...Name of Contact to search: ");
fflush(stdin);
scanf("%[^\n]",&querry);
l=strlen(querry);
fp=fopen("Contact.dll","r");
system("cls");
printf("\n\n::Search result for: 's'\n====================================\n", querry);
while(fread(&list,sizeof(list),1,fp)==1)
{
for(i=0;i<=l;i++)
{
name[i]=list.name[i];
name[1]='\0';
}
}
if (stricmp(name,querry)==0)
{
printf("\n..::Name\t: %s\n..::Phone\t: %ld\n....::Address\t %s\n.....::Email\t:%s\n", list.name,list.ph,list.add,list.email);
found++;
if(found%4==0)
{
printf("Press any key to continue..");
getch();
}
}
if(found==0)
{
printf("\n..:No match found");
}
else
{
printf("\n....match(s) found!",found);
}https://www.codeproject.com/script/Forums/Edit.aspx?fid=3785&floc=/Forums/3785/Managed-Cplusplus-CLI.aspx#
fclose(fp);
printf("\n.......Try again ? \n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
}while (ch==1); } break;
---------------------------------------------- while(fread....) --> what does this mean ?
if (stricmp(name,q
.... --> what does it mean ? Please explain for me , thank you very much! Hieu
Read the function documentation. They contain sections about the return values: fread | Microsoft Docs[^] _stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l | Microsoft Docs[^]
fread()
returns the number of successfully read items which is the same as the third function parameter when reading was successful. So thewhile
loop continues to be executed while reading is successful.stricmp()
returns zero when the passed strings are identical. So theif
block is executed when the passed strings are identical.