C manipulating struct arrays with pointers

Source: Internet
Author: User

Focus: Pointer self-add, point to next struct array cell

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 #defineMax 105 #defineMin 36 7typedefstructstu{8     Char*name;9     intAge ;Ten     intscore; One } Stu; A  - //input - voidInput (STU *); the voidOutput (STU *); - voidClean (STU *); -  - voidMainvoid) + { - Stu Student[min];  +Input (student);//equivalent to incoming &student[0] A  at output (student); - Clean (student); - } -  - voidInput (STU *student) - { in    Chartemp[ -]; -    intI=0; toPuts"Please input name"); +     while(I<min & Gets (temp)! = NULL & temp[0] !=' /' ) -    { theStudent->name = (Char*) malloc (strlen (temp) +1); *strcpy (student->name,temp); $           Panax NotoginsengPuts"Age ?"); -scanf"%d",&student->Age ); thePuts"score?"); +scanf"%d",&student->score); A            thei++; +student++;//pointer self-add, point to next array cell -            $            while(GetChar ()! ='\ n') $             Continue; -           -          if(i<min) thePuts"Next name"); -    }Wuyi  the } -  Wu voidOutput (STU *student) - { About    intI=0;  $     while(i<min) { -printf"%s---%d---%d\n",student->name,student->age,student->score); -i++; -student++; A    } +      the } -  $ voidClean (STU *student) the { the    intI=0;  the     while(i<min) { theFree (student->name);  -i++; instudent++; the    } the}

C manipulating struct arrays with pointers

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.