Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Members{
- char name[56];
- char id[7];
- float price;
- int lockerCode;
- }member;
- member *array;
- int arrSize = 0;
- void addMember(member *array, int arrSize, FILE *fp){
- array = (member*)realloc(array, sizeof(member) * (arrSize + 1));
- arrSize++;
- if(array == NULL){
- return 1;
- }
- member *member1 = malloc(sizeof(member));
- array[arrSize - 1] = member1;
- printf("Enter the name: ");
- fflush(stdin);
- scanf("%[^\n]s", member1.name);
- printf("Enter the credentials of a new member: ");
- fflush(stdin);
- scanf("%s", member1.id);
- printf("Enter the credentials of a new member: ");
- fflush(stdin);
- scanf("%f", &member1.price);
- printf("Enter the credentials of a new member: ");
- fflush(stdin);
- scanf("%d", &member1.lockerCode);
- fprintf(fp, "%s;%s;%f;%d\n", member1.name, member1.id, member1.price, member1.lockerCode);
- }
- void averageSubscribtion(member *array, int arrSize){
- double averagePrice;
- double price = 0;
- for(int i = 0; i < arrSize; i++){
- price = price + array[i].price;
- }
- averagePrice = price / arrSize;
- for(int n = 0; n < arrSize; n++){
- if(array[n].price < averagePrice){
- printf("%s - %s - f", array[n].name, array[n].id, array[n].price);
- }
- }
- }
- int main(){
- FILE *fp;
- fp = fopen("membersText.txt", "w");
- if(fp == NULL){
- printf("Error creating file");
- exit(1);
- }
- addMember(array, arrSize, fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement