LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2014, 02:13 PM   #1
khaliiid1992
LQ Newbie
 
Registered: Dec 2014
Posts: 1

Rep: Reputation: Disabled
help with two questions (struct to string)


Hi,
Could you guys help me with these two questions, I need to understand them before my final exam

Code:
typedef struct wood {
int len, wid, hei;
char *description;
} wood_t;


typedef struct wall {
wood_t primary, secondary, tertiary;
int materials_count;
int levels[20];
} wall_t;



wood_t planks[20];
wall_t vertical, horizontal;
wall_t *new_side;
wall_t *new_walls[];
1. Create a function to convert a wood_t to a string. Use the prototype:

char *tostring_wood_t( wood_t w );


2. Create a function to convert a wall_t to a string. Use the prototype:

char *tostring_wall_t( wall_t w );



really appreciate it.
 
Old 12-17-2014, 02:45 PM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
man sprintf.

The function sprintf can be used to build a string. If you run into difficulty with it post your efforts along with a clear description of the problem you're having.
 
Old 12-18-2014, 04:49 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,868
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I don't see the actual questions, nor the specification of the platform, but if it is Gnu, then asprintf is even better than sprintf.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Some questions about struct dentry involved with list ao.yuan.young Linux - Kernel 1 05-31-2009 08:08 PM
C struct string pointer problem j0hnsmith Programming 7 05-09-2009 10:37 AM
[C++] struct.string vs. string. Segfault caused. xtothat Programming 7 03-20-2009 05:27 AM
C: string to struct quantt Programming 20 02-10-2009 04:04 PM
adding to vector<string> in a struct niteshadw Programming 3 02-03-2005 07:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration