Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct test{
- char name[30];
- int age;
- };
- void addStudent(struct test *ptrTest,int *totalStudent){
- for(int i=0;i<2;i++){
- cout<<"nInsert the name: ";
- cin.sync();
- cin.getline(ptrTest->name,sizeof(ptrTest->name));
- cout<<"nInsert the age: ";
- cin.sync();
- cin>>ptrTest->age;
- *totalStudent+=1;
- }
- }
- void showStudent(struct test *ptrTest,int totalStudent){
- for(int i=0;i<totalStudent;i++){
- cout<<"nName: "<<ptrTest->name;
- cout<<"nAge: "<<ptrTest->age;
- }
- };
- int main()
- {
- struct test t;
- addStudent(&t,&totalStudent);
- showStudent(&t,totalStudent);
- return 0;
- }
- int main()
- {
- struct test t;
- // LIKE THIS
- int totalStudent;
- addStudent(&t,&totalStudent);
- showStudent(&t,totalStudent);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement