KOFIOWUSU847's blog

By KOFIOWUSU847, 11 years ago, In English

include

include

using namespace std;

void printstudent(student *Student);

typedef struct { char name[50];

}student;

int main() { student student1; strcpy(student1.name,"Douglas Brown"); printstudent(&student 1); } void printstudent(student *Student) { cout<name<<endl; }

  • Vote: I like it
  • -17
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

For better view :

#include <iostream> // let me
#include <cstring>  // guess :)
using namespace std;

typedef struct {
	char name[50];
} student;

void printstudent(student &Student);

int main() {
	student student1;
	strcpy(student1.name, "Douglas Brown");
	printstudent(student1);
}

void printstudent(student &Student) {
	cout << Student.name << endl;
}

So what are you asking ?? :S

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i want to use this operator -> instead of . dot and wants pointer *Student instead.

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      As far as I understand you, you are having compilation error.

      1. You mistyped &student 1. It should be &student1.
      2. You need to declare struct student before printstudent prototype.

      Here is the correct one:

      #include <iostream>
      #include <cstring>
      using namespace std;
      
      typedef struct {
      	char name[50];
      } student;
      
      void printstudent(student *Student);
      
      int main() {
      	student student1;
      	strcpy(student1.name, "Douglas Brown");
      	printstudent(&student1);
      }
      
      void printstudent(student *Student) {
      	cout << Student->name << endl;
      }