#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define AVAILABLE 0
#define TAKEN 1
#define TRUE 1
#define FALSE 0
typedef struct{
int weight;
char name[10];
int neuteredFlag;
} CAT;
void printCat(CAT*);
void neuter(CAT*);
main(){
CAT pCats[10];
char *names[6] = {"Paul" , "Neko", "Gato", "Bert", "Ann" , "Deb" };
int cat_names[6] = { { AVAILABLE } };
int catIndex;
srand( time( NULL ) );
pCats = malloc(sizeof(CAT));
catIndex = rand() % 6;
while(cat_names == TAKEN){
catIndex = rand() % 6;
}
// Would this be considered a heap?
// Do I need to change -> to . for it to be a stack?
strcpy(pCats->name, names[catIndex]);
pCats->weight = rand() % 30 + 1;
pCats->neuteredFlag = rand() % 2;
printCat(pCats);
neuter(pCats);
printCat(pCats);
system("Pause");
}
void printCat(CAT *pCats){
printf("Name Weight Neutered Flag\n");
printf("==== ====== =============\n\n");
//?? Need help with for loop ??
if(pCats->neuteredFlag == FALSE){
printf("%s%6i No\n\n", pCats->name, pCats->weight);
}
else{
printf("%s%6i Yes\n\n", pCats->name, pCats->weight);
}
}
void neuter(CAT *pCats){
if(pCats->neuteredFlag == TRUE){
printf("%s has already been neutered.\n\n", pCats->name);
}
else{
printf("Note: %s has now been successfully neutered.\n\n", pCats->name);
pCats->neuteredFlag = TRUE;
}
}
Thanks for any helpful replies.
EDIT: Indented code correctly. I added comments throughout the code that ask questions.
This post has been edited by whatThewhat: 19 April 2010 - 12:42 PM

New Topic/Question
Reply




MultiQuote




|