C language ---- function pointer

Source: Internet
Author: User

C language ---- function pointer
Callback Function

1. function pointer Parameters

2. Callback Process

Sample Code
/// Main. m // C_Project_12 // Created by on 15/3/26. // Copyright (c) 2015. All rights reserved. // # import
  
   
// Exercise questions in the classroom: Write a function to search for students with scores higher than 90? Add "? Gao fushuai ". // 1. define the struct type typedef struct student {char name [20]; float score;} Student; Student * generateStudentsInfo (int count) {Student * stus = malloc (sizeof (Student) * count); for (int I = 0; I <count; I ++) {printf ("enter the information of student % d \ n", I + 1); printf ("name:"); scanf ("% s ", (stus + I)-> name); printf ("score:"); scanf ("% f", & (stus + I)-> score );} return stus;} void printStudentsInfo (Student * stus, int count); void printStudentsInfo (Student * stus, int count) {printf ("\ n --------------------------- \ n "); for (int I = 0; I <count; I ++) {printf ("Name: % s \ t score: %. 2f \ n ", (stus + I)-> name, (stus + I)-> score);} printf (" \ n ------------------------- \ n ");} void modifyName (char * name); void modifyName (char * name) {strcat (name, "-Gao fushuai");} void searchStudentInfo (Student * stus, int count, float score, void (* point) (char *); void searchStudentInfo (Student * stus, int count, float score, void (* point) (char *)) {for (int I = 0; I <count; I ++) {if (stus + I)-> score) {point (stus + I) -> name) ;}} int main (int argc, const char * argv []) {Student * stus = generateStudentsInfo (2); printStudentsInfo (stus, 2 ); searchStudentInfo (stus, 2, 90, modifyName); printStudentsInfo (stus, 2); return 0 ;}
  

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.