![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pointer to a struct (with pointers) *** glibc detected *** double free | jatoo | High Level Programming | 1 | 12-05-2008 08:31 AM |
| Struct Array | micmac700 | High Level Programming | 1 | 12-13-2006 01:07 PM |
| struct tm problem | bankpro | High Level Programming | 4 | 01-20-2006 06:51 AM |
| save a struct | kall_ANSI | High Level Programming | 2 | 10-29-2004 11:42 AM |
| Struct Initialization | amatsaka | High Level Programming | 4 | 12-20-2002 10:25 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
C++ struct pointers & functions
Hi All,
My latest assignment (practice not coursework!) is to write prototype interactive exam/test console application. I've used structs to store the question information (not sure if this was the best way to do it?) and I have the following code that outputs each question and it's possible answers: Code:
cout << endl; cout << "Q" << iIndex << ": " << sQuestions[iIndex].caQuestion << endl; cout << endl; cout << "\tA: " << sQuestions[iIndex].caPossibleAnswer1 << endl; cout << "\tB: " << sQuestions[iIndex].caPossibleAnswer2 << endl; cout << "\tC: " << sQuestions[iIndex].caPossibleAnswer3 << endl; cout << "\tD: " << sQuestions[iIndex].caPossibleAnswer4 << endl; cout << endl; I'm also using the following code to load data into my struct. Visual C++ gives me warnings about using strcpy, is there a better way of doing this? Code:
// load the question data (if you can figure out pointers you could put this in a function) strcpy(sQuestions[0].caQuestion, "What statement separator is commonly used in a for loop?"); strcpy(sQuestions[0].caPossibleAnswer1, "semicolon"); strcpy(sQuestions[0].caPossibleAnswer2, "comma"); strcpy(sQuestions[0].caPossibleAnswer3, "colon"); strcpy(sQuestions[0].caPossibleAnswer4, "quote"); sQuestions[0].cCorrectAnswer = 'A'; p. 4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course): e-Quals IT Practitioners Diploma - C++ Programming Farnborough Tech. UK. Dr. Usman Abdullahi ---------- Post updated at 06:34 PM ---------- Previous update was at 03:24 PM ---------- Hi All, Doing some digging around I've found the answer to my problem - on page 168 of Herbert Schildt's "C++ The Complete Reference" I found a section entitled "Passing Entire Structures to Functions". So I modified my function to look like this: Code:
void displayQuestions(struct sQuestionFormat sQuestions, int iIndex)
{
cout << endl;
cout << "Q" << iIndex << ": " << sQuestions.caQuestion << endl;
cout << endl;
cout << "\tA: " << sQuestions.caPossibleAnswer1 << endl;
cout << "\tB: " << sQuestions.caPossibleAnswer2 << endl;
cout << "\tC: " << sQuestions.caPossibleAnswer3 << endl;
cout << "\tD: " << sQuestions.caPossibleAnswer4 << endl;
cout << endl;
}
Code:
displayQuestions(sQuestions[iIndex], iIndex); Code:
struct sQuestionFormat sQuestions[10]; ![]() Last edited by pondlife; 2 Weeks Ago at 11:45 AM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|