Before I go on with this program, I'd like to know if what I've done thus far is ok in terms of valid code. Please, if you see something wrong, tell me so that I can fix it.
TIA... formatting doesn't look so good in preview mode... hmm
Code:#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> typedef struct data1 { char questions[25][75]; char iname[20]; char ipassw[15]; int num2ask; } progD; void newD(progD *temp) { /* * newD() * * purpose: to store initial information provided * by the instructor, pw, and the set of * questions to be asked. * * status: Incomplete - struct "data1," output file, * #defines, pw, entering * questions as a sep funct ********************************************************/ char *n, num[5]; int start=0; printf("Please enter your name: "); fgets(temp->iname, 20, stdin); /* any nasty side effects from doing this? */ temp->iname[strlen(temp->iname)-1] = '\0'; printf("\n%s, how many questions will you ask? (MAX = %d): ", temp->iname, 25); fgets(num, sizeof(num), stdin); num[strlen(num)-1] = '\0'; /* if num is not in the desired range, then output such to correct */ /* working as expected? not all is as it seems.... */ while((temp->num2ask = (int)strtol(num, &n, 10)) > 25 || temp->num2ask < 1) { /* some conditions still sneak through :( */ printf("\nSorry %s, %d is not a valid value.\n", temp->iname, temp->num2ask); printf("Please enter a value between 1 and 25: "); fgets(num, sizeof(num), stdin); } while(start < temp->num2ask) /* get those questions */ { /* replace test with local var later on */ /* real mode dos target, so question length is 80 - "-> " to avoid line wrap */ printf("\nYou have %d question(s) remaining\n", (temp->num2ask < 25 ? temp->num2ask-start : 25-start)); printf("-> "); /* above will be modifed at some point */ fgets(temp->questions[start], 75, stdin); temp->questions[start][strlen(temp->questions[start])-1] = '\0'; start++; } } int main(void) { int i; progD user; newD(&user); i=0; printf("\n\n%s, you asked the following\n\n", user.iname); while(i < user.num2ask) printf("%s\n", user.questions[i++]); return 0; }



LinkBack URL
About LinkBacks



.