> 7+ Strcmp 使い方 References - Umnaz

7+ Strcmp 使い方 References

strcmp in c YouTube
strcmp in c YouTube from www.youtube.com

Introduction

If you are someone who is interested in programming or is already a programmer, you must have come across the term strcmp. It is a commonly used function in the C programming language that is used to compare strings. In this article, we will take a closer look at strcmp and understand its usage in detail.

What is strcmp?

strcmp is a built-in function in the C programming language that is used to compare two strings. It takes two arguments, which are the strings that need to be compared, and returns an integer value. If both strings are the same, the function returns 0. If the first string is greater than the second string, it returns a positive value. If the first string is smaller than the second string, it returns a negative value.

Example:

Let's take an example to understand this better. Consider the following code: ``` #include #include int main() { char str1[20] ="Hello"; char str2[20] ="World"; int result = strcmp(str1, str2); printf("%d", result); return 0; } ``` In the code above, we have two strings, 'Hello' and 'World', and we are using the strcmp function to compare them. Since the first string is smaller than the second string, the function returns a negative value, which is -15. This value can be used to determine the order of the strings.

Usage of strcmp

Now that we know what strcmp is, let's take a look at its usage. The strcmp function is commonly used in programs that involve string manipulation. It is used to compare two strings to determine if they are the same or not. It can also be used to sort strings in alphabetical order.

Example:

Consider the following code: ``` #include #include int main() { char str1[20] ="Apple"; char str2[20] ="Banana"; char str3[20] ="Orange"; int result1 = strcmp(str1, str2); int result2 = strcmp(str2, str3); int result3 = strcmp(str1, str3); if(result1 < 0) printf("Apple comes before Banana"); else if(result1 > 0) printf("Banana comes before Apple"); else printf("Apple and Banana are the same"); if(result2 < 0) printf("\nBanana comes before Orange"); else if(result2 > 0) printf("\nOrange comes before Banana"); else printf("\nBanana and Orange are the same"); if(result3 < 0) printf("\nApple comes before Orange"); else if(result3 > 0) printf("\nOrange comes before Apple"); else printf("\nApple and Orange are the same"); return 0; } ``` In the code above, we have three strings, 'Apple', 'Banana', and 'Orange', and we are using the strcmp function to compare them. We are using the results of the function to determine the order of the strings. The output of the code will be: ``` Apple comes before Banana Banana comes before Orange Apple comes before Orange ```

Conclusion

In conclusion, the strcmp function is a powerful tool in the C programming language that is used to compare strings. It is commonly used in programs that involve string manipulation and sorting. By understanding the usage of strcmp, you can write more efficient and effective programs.

Subscribe to receive free email updates:

Related Posts :

  • Must Know オシロスコープ 使い方 Ideasオシロスコープで Seeeduino のタイマー処理を確認してみる Tech Blog by Akanuma Hiroaki from blog.akanumahiroaki.comIntroductionOscilloscopes are essential tools for… Read More...
  • 7+ It 使い方 References【無料モニター】置き場所や使い方は自由自在♪ベルメゾンの折りたためるラックを使いたい方、大募集! RoomClip mag 暮らしと from roomclip.jpIntroduction In today's tech-savvy world, IT has become a… Read More...
  • 9+ Due 使い方 Ideasウクレレな毎日♪ディミニッシュコード使い方♪ from blog.livedoor.jpIntroductionAre you tired of keeping track of all your tasks and deadlines on separate platforms… Read More...
  • 7+ 石灰 の 使い方 Article石灰窒素の使い方について 営農ニュース JAちちぶ【ちちぶ農業協同組合】 from www.ja-chichibu.jpThe Benefits of Lime Lime, also known as calcium oxide, has been used for centur… Read More...
  • Must Know セザンヌ 下地 使い方 Articleセザンヌ皮脂テカリ防止下地の違いは?人気下地の使い方を徹底解説!|NOIN(ノイン) from noin.shop Introduction Cezanne primer is a popular makeup product that has gained a lot of … Read More...

0 Response to "7+ Strcmp 使い方 References"

Posting Komentar