Can someone please fix my errors in code?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct person {
char name[30];
char last_name[30];
int age;
float wage;
} person1;
struct person {
char name[30];
char last_name[30];
int age;
float wage;
} person2;
struct person {
int age;
float wieght;
char name[30];
};
typedef struct people {
char name[30];
char last_name[30];
int age;
float wage;
}person2;
struct pers {
int age;
double wieght;
};
int main() {
//first Example:
printf("Example 1: \n");
scrcpt(person1.name, "James Bond");
person1.age = 55;
person1.wage = 17.7;
printf("The name of this person is %s. \n", person1.name);
printf("The age of this person is %s. \n", person1.age);
printf("The wage of this person is %s. \n", person1.wage);
printf("\n \n");
//---------------------------------------------------------------------------------------------------
// 2nd Example:
printf("Example 2: \n");
person2 student1;
strcpy(student1.name, "James Bond");
person1.age = 55;
person1.wage = 17.7;
printf("The name of this person is %s. \n", person1.name);
printf("The age of this person is %s. \n", person1.age);
printf("The wage of this person is %s. \n", person1.wage);
printf("\n \n");
//---------------------------------------------------------------------------------------------------
// 3rd Example:
// In this example, we would like to get access for menbers using Pointer
// 2nd Example:
printf("Example 3: \n");
struct pers* personPtr, person11;
personPtr = &person11;
printf("Please insert thae age of this person: \n");
scanf("%d", &personPtr->age);
printf("Please insert the wieght of this person: \n");
scanf("%d", &personPtr->wieght);
printf("The age of this person is %d. \n", personPtr->age);
printf("The wieght of this person is %s. \n", personPtr->wieght);
struct person* ptr;
int n;
printf("Please, enter the number of the persons that are going to be in this struct: ");
scanf("&d", &n);
ptr = (struct persons*)malloc(n * sizeof(struct person));
for (int i = 0; i < n; i++) {
printf("Please insert the name followed by age of the person, serperated with a space: ");
scanf("%s %d", (ptr + i)->age);
}
printf("Let's dispaly the inserted names and thier ages: ");
for (int i = 0; i < n; i++) {
printf("Name: %s - Age: %d \n", (ptr + i)->name, (ptr + i)->age);
}
return 0;
}
Can someone please fix my errors in code?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct person {
char name[30];
char last_name[30];
int age;
float wage;
} person1;
struct person {
char name[30];
char last_name[30];
int age;
float wage;
} person2;
struct person {
int age;
float wieght;
char name[30];
};
typedef struct people {
char name[30];
char last_name[30];
int age;
float wage;
}person2;
struct pers {
int age;
double wieght;
};
int main() {
//first Example:
printf("Example 1: \n");
scrcpt(person1.name, "James Bond");
person1.age = 55;
person1.wage = 17.7;
printf("The name of this person is %s. \n", person1.name);
printf("The age of this person is %s. \n", person1.age);
printf("The wage of this person is %s. \n", person1.wage);
printf("\n \n");
//---------------------------------------------------------------------------------------------------
// 2nd Example:
printf("Example 2: \n");
person2 student1;
strcpy(student1.name, "James Bond");
person1.age = 55;
person1.wage = 17.7;
printf("The name of this person is %s. \n", person1.name);
printf("The age of this person is %s. \n", person1.age);
printf("The wage of this person is %s. \n", person1.wage);
printf("\n \n");
//---------------------------------------------------------------------------------------------------
// 3rd Example:
// In this example, we would like to get access for menbers using Pointer
// 2nd Example:
printf("Example 3: \n");
struct pers* personPtr, person11;
personPtr = &person11;
printf("Please insert thae age of this person: \n");
scanf("%d", &personPtr->age);
printf("Please insert the wieght of this person: \n");
scanf("%d", &personPtr->wieght);
printf("The age of this person is %d. \n", personPtr->age);
printf("The wieght of this person is %s. \n", personPtr->wieght);
struct person* ptr;
int n;
printf("Please, enter the number of the persons that are going to be in this struct: ");
scanf("&d", &n);
ptr = (struct persons*)malloc(n * sizeof(struct person));
for (int i = 0; i < n; i++) {
printf("Please insert the name followed by age of the person, serperated with a space: ");
scanf("%s %d", (ptr + i)->age);
}
printf("Let's dispaly the inserted names and thier ages: ");
for (int i = 0; i < n; i++) {
printf("Name: %s - Age: %d \n", (ptr + i)->name, (ptr + i)->age);
}
return 0;
}