| | |
C Program solution needed...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 2
Reputation:
Solved Threads: 0
Hi friends,
As i a writting small C program to pass the structure pointer in the function. i am endup with small problem, plz let me know how to crack this one?
/////////////////
As i a writting small C program to pass the structure pointer in the function. i am endup with small problem, plz let me know how to crack this one?
/////////////////
C++ Syntax (Toggle Plain Text)
void function1(void *); void main() { int size_offset = 0; typedef struct { int a; int b; int c; char ch; }A; A *pst = NULL; pst = (A*)malloc(sizeof(A)*1); function1((void*)pst); } void function1(void *pStr) { // As i need to intialize the structure members. i want to access it's me mbers. // How can i know the structure's // memory layout in this function? //Conditions: //1. i do not want to declare the structure as global or static. //2. I will pass the structure pointer as void pointer. }
Your type A, can it be outside of the main function? Still your pst struct is local beside that.
NOTE: Instead of void main use int main.
if type A is in front of int main.
NOTE: Instead of void main use int main.
C++ Syntax (Toggle Plain Text)
void function1(void *pStr) { A * ptmp = (A *) pStr; ptmp->a = 0; ptmp->b = 0; ptmp->c = 0; ptmp->ch = '\0'; }
If you want to win, you must not loose (Alan Ford)
>>pst = (A*)malloc(sizeof(A)*1);
1. The "*1" is unnecessary and spurious.
2. C programs do not require typecasting. So remove that typecast. If your compiler complains then your are apparently writing a c++ program.
3. Move that structure above the functuion main() so that it is visible to all other functions. Then change function1 parameter to use that structure instead of passing a void pointer. You will need to change the function prototype at the top of your program too.
4. Come up with a better naming convention than "A". That is a sure sign of poor programming habits. You are new at this, so learn the right way at the very start.
1. The "*1" is unnecessary and spurious.
2. C programs do not require typecasting. So remove that typecast. If your compiler complains then your are apparently writing a c++ program.
3. Move that structure above the functuion main() so that it is visible to all other functions. Then change function1 parameter to use that structure instead of passing a void pointer. You will need to change the function prototype at the top of your program too.
C++ Syntax (Toggle Plain Text)
void function1(A *pStr) { // blabla }
4. Come up with a better naming convention than "A". That is a sure sign of poor programming habits. You are new at this, so learn the right way at the very start.
Last edited by Ancient Dragon; Oct 18th, 2006 at 10:30 am.
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
plz solve this problem
Consider the ADT set that represents a collection of integers. The ADT should support standard set operations:
S = init();
/* Initialize S to the empty set */
isEmpty(S);
/* Return true if and only if S is the empty set */
isSingleton(S);
/* Return true if and only if S contains only one element */
isMember(S,a);
/* Return true if and only if a is a member of the set S */
S = addElement(S,a);
/* Add the element a to the set S. If a is already in S,
there will be no change, else a new element is to be inserted. */
S = delElement(S,a);
/* Remove the element a from the set S. No change if a is not
a member of S. */
S = union(U,V);
/* Assign to S the union of the sets U and V */
S = intersection(U,V);
/* Assign to S the intersection of the sets U and V */
S = difference(U,V);
/* Assign to S the set difference U - V */
S = symmDiff(U,V);
/* Assign to S the symmetric difference (U - V) union (V - U) */
printElements(S);
/* Print the elements of the set S */
Implement the set ADT using dynamic arrays. You will need to use realloc to change the size of an array that was dynamically allocated earlier.
Consider the ADT set that represents a collection of integers. The ADT should support standard set operations:
S = init();
/* Initialize S to the empty set */
isEmpty(S);
/* Return true if and only if S is the empty set */
isSingleton(S);
/* Return true if and only if S contains only one element */
isMember(S,a);
/* Return true if and only if a is a member of the set S */
S = addElement(S,a);
/* Add the element a to the set S. If a is already in S,
there will be no change, else a new element is to be inserted. */
S = delElement(S,a);
/* Remove the element a from the set S. No change if a is not
a member of S. */
S = union(U,V);
/* Assign to S the union of the sets U and V */
S = intersection(U,V);
/* Assign to S the intersection of the sets U and V */
S = difference(U,V);
/* Assign to S the set difference U - V */
S = symmDiff(U,V);
/* Assign to S the symmetric difference (U - V) union (V - U) */
printElements(S);
/* Print the elements of the set S */
Implement the set ADT using dynamic arrays. You will need to use realloc to change the size of an array that was dynamically allocated earlier.
A - no one is likely to solve your problem for you. You must attempt the solution, show your work, and we'll help you get to the solution you need.
B - don't ask a question by replying to an unrelated thread - that's hijacking and not appreciated
B+ - really don't do this with a thread that's over 2 years old!
Please read the sticky posts at the top of this forum to learn the rules that will make your visit here more pleasant and productive.
B - don't ask a question by replying to an unrelated thread - that's hijacking and not appreciated
B+ - really don't do this with a thread that's over 2 years old!
Please read the sticky posts at the top of this forum to learn the rules that will make your visit here more pleasant and productive.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- How to run a *.exe file in Java (Java)
- My 1st C++ program advice needed (C++)
- Reformating- how can i back up (Windows NT / 2000 / XP)
- chars and floats (C)
- isdesign.ocx and mscomct2.ocx (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Interesting String Encryption
- Next Thread: sort even and odd numbers from an array
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






