|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: |
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "database.h"
int main(){
//hold value of how many records in storage
int records;
char numStr[MAX_NUMSTR] = "";
//loop counter
int count = 0;
//retrieve now many records to add to the database
printf("How many cd records do you have? You can enter in a max of 200 records ");
fgets(numStr,sizeof(numStr), stdin);
sscanf(numStr, "%d", &records);
//array of cd records
album *cd = malloc(records*(sizeof(cd)));
if(cd == NULL){
puts("Error: You do not have enough memory to run this program.");
exit(1);
}
//store record information in the album array
for(count = 0; count < records; count++){
readAlbum(&cd[count]);
}
for(count = 0; count < records; count++)
print_cd(&cd[count]);
//free memory that was allocated from strdup
for(count = 0; count < records; count++){
free(cd[count].title);
free(cd[count].artist);
}
free(cd);
return 0;
}
//display records
void print_cd(album *ab){
puts("----------------------------------------");
printf("%25s\n", ab->title);
puts("----------------------------------------");
printf("Title: %s\n", ab->title);
printf("Artist: %s\n", ab->artist);
printf("Tracks: %d\n", ab->tracks);
if(ab->albumSingle == 1)
printf("Album/Single: Album\n");
else
printf("Album/Single: Single\n");
printf("Price: $%.2f\n", ab->price);
}
void readAlbum(album *ab){
ab->title = read_dyn_string("CD Title: ");
ab->artist = read_dyn_string("Artist: ");
ab->tracks = read_int("Tracks: ");
ab->type = read_char("Is the a album type y for yes or n for no: ");
if( yesno(&ab->type) == 1)
ab->albumSingle = ALBUM;
else
ab->albumSingle = SINGLE;
ab->price = read_float("Price: ");
}
//pause function
void enter(char* str){
printf("%s", str);
getchar();
}
//yes or no function
int yesno(char *answer){
char numStr[MAX_NUMSTR] = "";
char yn;
do{
if(tolower(*answer) == 'y')
return 1;
else if(tolower(*answer) == 'n')
return 0;
else{
printf("Error: enter y for yes or n for no\n");
fgets(numStr,sizeof(numStr), stdin);
sscanf(numStr, " %c",&yn);
*answer = yn;
}
}while(1);
}
//read integer input
int read_int(char *prompt){
int i = 0;
char numStr[MAX_NUMSTR] = "";
fputs(prompt, stdout);
fgets(numStr,sizeof(numStr), stdin);
sscanf(numStr, "%d", &i);
return i;
}
//read character input
char read_char(char *prompt){
char c;
char numStr[MAX_NUMSTR] = "";
fputs(prompt, stdout);
fgets(numStr,sizeof(numStr), stdin);
sscanf(numStr, " %c",&c);
return c;
}
//read float input
float read_float(char *prompt){
float f = 0.0;
char numStr[MAX_NUMSTR] = "";
fputs(prompt, stdout);
fgets(numStr,sizeof(numStr), stdin);
sscanf(numStr, "%f", &f);
return f;
}
//read a string input
char *read_dyn_string(char* prompt){
char answer[MAX_STR];
fputs(prompt, stdout);
fgets(answer,sizeof(answer), stdin);
trim_newline(answer);
return strdup(answer);
}
//remove newline character on a string
void trim_newline(char* str){
if (str[strlen(str)-1] == '\n')
str[strlen(str)-1] = '\0';
}
|
Advertisement
| Hall of Fame |