Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. please explain this lines of code

please explain this lines of code

Scheduled Pinned Locked Moved Managed C++/CLI
comtoolsregexquestion
3 Posts 3 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hieu Ngo
    wrote on last edited by
    #1

    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

    L J 2 Replies Last reply
    0
    • H Hieu Ngo

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Hieu Ngo

        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

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        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 the while loop continues to be executed while reading is successful. stricmp() returns zero when the passed strings are identical. So the if block is executed when the passed strings are identical.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups