How to find a string in an array of strings in C

Поділитися
Вставка
  • Опубліковано 10 січ 2022
  • Source code can be found here:
    code-vault.net/lesson/qwc2wv1...
    ===== Support us through our store =====
    code-vault.net/shop
    ===== Check out our website =====
    code-vault.net
    ===== Check out our Discord server =====
    discord.code-vault.net

КОМЕНТАРІ • 27

  • @MuksEmmaN
    @MuksEmmaN 2 роки тому +2

    Really appreciate this video.
    Your way of teaching is so powerful

  • @aatishlanghee
    @aatishlanghee 2 роки тому

    Hi, Thank you for this amazing video.
    Can you please create complete C language tutorials playlist from beginner to advance in a practical hands on way. It would be good for us to get some hands on experience on the industry based problems.

    • @CodeVault
      @CodeVault  2 роки тому

      I'll look into it. Thanks for the recommendation!

  • @kapellimestari0078
    @kapellimestari0078 2 роки тому

    very good

  • @pcuser80
    @pcuser80 2 роки тому

    You can also use strcasecmp does the same as strcmp but ignores the case.

    • @CodeVault
      @CodeVault  2 роки тому +1

      Oh cool! I didn''t even know about the strcasecmp function. Thanks!
      I'm still on the fence about covering non-standard functions on the channel though (same reason why I didn't use strlwr in this video)
      What do you think? Should I start covering all these non-standard yet popular functions?

    • @pcuser80
      @pcuser80 2 роки тому

      @@CodeVault Yes Please

  • @bushraw66
    @bushraw66 2 роки тому

    Thank you so much for this video.
    I have a question tho, at 6:27
    can't we just use else{} instead whar you wrote in line 20?

    • @CodeVault
      @CodeVault  2 роки тому

      Else for the if in the for loop you mean?

    • @bushraw66
      @bushraw66 2 роки тому

      @@CodeVault yes , instead of writing that i>=3 does it work with just an else ?

    • @CodeVault
      @CodeVault  2 роки тому

      Not really, since the message would be printed for every element that is not equal to the one you're searching

  • @NoNameAtAll2
    @NoNameAtAll2 2 роки тому +1

    can you repeat please the need for `input[strlen(input)-1]=0` line?
    since there is already a null character, why overwrite last input char with 2nd one?

    • @0llie_K
      @0llie_K 2 роки тому

      A new line character: '
      ' is read as the last input char when the return key is pressed, In this instance it is not wanted and is therefore removed by replacing it with a null terminator.

    • @CodeVault
      @CodeVault  2 роки тому

      Take a look at the video I pointed to: code-vault.net/lesson/yxllgxvfmb:1603733521595
      It explains this and why we use fgets instead of scanf

    • @pcuser80
      @pcuser80 2 роки тому +1

      @@CodeVault I use this always for removing end of line , works for windows and linux input[strcspn(input, "
      ")] = 0;

  • @GillesHenrard
    @GillesHenrard 2 роки тому

    Would a "do...while" loop with a flag variable not be cleaner than a full-fledged for loop with a break instruction?

    • @CodeVault
      @CodeVault  2 роки тому +1

      A bit maybe. You'd still need to have the definition of i, increment and the condition somewhere in that loop.
      int i = 0;
      do {
      // ...
      } while (i < 3 && strcmp(arr[i], input) != 0);
      I could be biased but reading a for loop with a break is much easier to understand than a do...while loop that looks like this
      You can use whichever you feel is right for you though!

    • @GillesHenrard
      @GillesHenrard 2 роки тому

      @@CodeVault I was more thinking about something like :
      int i = 0, notfound = 0;
      do {
      notfound = strcmp(arr[i], input);
      i++;
      } while (i < 3 && notfound);
      But as you said, except for memory or execution time constraints, only the dev's taste differs :)

  • @soufianeamimi
    @soufianeamimi 2 роки тому

    Can u explain about the oriented objects in c++

    • @CodeVault
      @CodeVault  2 роки тому +1

      Yes! I plan on making a large series about OOP

    • @soufianeamimi
      @soufianeamimi 2 роки тому

      @@CodeVault oooh that would be awsome

  • @saurabhatre2158
    @saurabhatre2158 Рік тому

    Sir video is helpful but I want to search( 4 ft × 15 inch ,0.9 21) as a whole string to be found can you help me please ( I want to use data structure too but it says _parameter error
    The current program finds only till
    4 ft only 4 digits i want whole string to be searched at once with data structure please see to it and send source code to improve it

    • @CodeVault
      @CodeVault  Рік тому

      There are two options: You can either manually iterate over the string and check if the string is what you're searching for or, use a regex library (if you need to find any number in the string)

    • @saurabhatre2158
      @saurabhatre2158 Рік тому

      @@CodeVault
      Sir, thanks for info
      But please share source code
      Array a={(4 ft x 15 inch, 0.93,21),(4ft x 15 inch ,0.93,21),(4ft x 12 inch),0.93,21)}
      Output: (4 ft x 15 inch, 0.93,21) =>2
      (4ft x 12 inch),0.93,21) =>1

  • @k_ushagra
    @k_ushagra 2 роки тому

    and this is how we know you favourite fruit or colour is Orange.. 😛😜

  • @shivagthegamer4933
    @shivagthegamer4933 Рік тому

    Thanks, but I want function of it

    • @CodeVault
      @CodeVault  Рік тому

      You could copy everything in a function and set the array of strings as parameter and the result as a return