String exercise -- enter keywords to search for songs, and enter keywords in strings

Source: Internet
Author: User

String exercise -- enter keywords to search for songs, and enter keywords in strings

# Include <stdio. h> # include <string. h> // use the strstr () function to find the string char tracks [] [80] = {// song list "I left my heart in Harvard Med School", "Newark, newark-a wonderful town "," Dancing with a Dork "," From here to maternity "," The girl from Iwo Jima ",}; void find_track (char search_for []) {int I; for (I = 0; I <5; I ++) {if (strstr (tracks [I], search_for )) // display all matching songs printf ("Track % I: '% s' \ n", I, tracks [I]) ;}} int main () {char search_for [80]; printf ("Search for:"); // enter the Search keyword fgets (search_for, 80, stdin); search_for [strlen (search_for) -1] = '\ 0'; find_track (search_for); // display the matched song return 0 ;}

 

Running result:

 

Key Points

  • You can use char strings [...] [...] to create an array.
  • The first group of square brackets is used to access the outer array.
  • The second set of square brackets is used to access the elements in each inner array.
  • With the string. h header file, you can use the string processing function in the C standard library.
  • You can create multiple functions in a C program, but the computer always runs main () first ().

Problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.