473,490 Members | 2,486 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I am truly LOST. I would love some help.

I got this project for my class and I'm totally lost as to how to copy
the 1d array with the bone name into a 2d array using this supposed
strncpy function I'm supposed to create. I believe the teacher wants us
to make the function and not use the library function.

Here's the info:

Write a C++ program that
Opens the file for input using the ifstream facility (see example
program from class).
Declares a two dimensional character array to store the bones from the
input file.
Reads each line of the file and stores the bone in the array position
indicated by the number at the start of the line (e.g., toe is the
first element, foot is the second, etc.; remember that C++ array
indices start with 0). As you process the file, read each bone into a
separate character array and then use the strncpy() function you will
write (see below) to copy the bone name into the main array.
Loops through the main bone array and builds up a long character string
saying which bone is connected to which (e.g., "The toe bone is
connected to the foot bone\nThe foot bone is connected to the ....").
The string should contain a newline character separating each statement
of connectedness. To do this, use the strcat() function you will write
(see below).
Prints the long character string of connectedness to the console.
Your program will use following three functions that you will write.
These functions should use pointer arithmetic rather than array
notation.

void strncpy(char *dest, char *src, int numchr);
Copies the string pointed to by src to the character array pointed to
by dest. numchr is the number of characters to copy. After the copy
operation, dest should be null terminated.

int strlen(char *str)
returns the number of characters in the null-terminated string pointed
to by str.

void strcat(char *dest, char *src)
appends the null-terminated string pointed to by src to the
null-terminated string pointed to by dest. Moves dest's terminating
null to the end of the new string.

Hints:

When you call strncpy, you can use strlen to determine the length of
src
Make sure you make your character arrays big enough
AND HERE IS THE TEXT FILE CONTENT BEING READ:

2 foot
4 leg
10 head
3 ankle
6 thigh
7 hip
1 toe
5 knee
8 back
9 neck

Sep 10 '06 #1
3 2004

"c++dummy" <ru***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I got this project for my class and I'm totally lost as to how to copy
the 1d array with the bone name into a 2d array using this supposed
strncpy function I'm supposed to create. I believe the teacher wants us
to make the function and not use the library function.

Here's the info:

Write a C++ program that
Opens the file for input using the ifstream facility (see example
program from class).
Declares a two dimensional character array to store the bones from the
input file.
Reads each line of the file and stores the bone in the array position
indicated by the number at the start of the line (e.g., toe is the
first element, foot is the second, etc.; remember that C++ array
indices start with 0). As you process the file, read each bone into a
separate character array and then use the strncpy() function you will
write (see below) to copy the bone name into the main array.
Loops through the main bone array and builds up a long character string
saying which bone is connected to which (e.g., "The toe bone is
connected to the foot bone\nThe foot bone is connected to the ....").
The string should contain a newline character separating each statement
of connectedness. To do this, use the strcat() function you will write
(see below).
Prints the long character string of connectedness to the console.
Your program will use following three functions that you will write.
These functions should use pointer arithmetic rather than array
notation.

void strncpy(char *dest, char *src, int numchr);
Copies the string pointed to by src to the character array pointed to
by dest. numchr is the number of characters to copy. After the copy
operation, dest should be null terminated.

int strlen(char *str)
returns the number of characters in the null-terminated string pointed
to by str.

void strcat(char *dest, char *src)
appends the null-terminated string pointed to by src to the
null-terminated string pointed to by dest. Moves dest's terminating
null to the end of the new string.

Hints:

When you call strncpy, you can use strlen to determine the length of
src
Make sure you make your character arrays big enough
AND HERE IS THE TEXT FILE CONTENT BEING READ:

2 foot
4 leg
10 head
3 ankle
6 thigh
7 hip
1 toe
5 knee
8 back
9 neck
A 2 dimentional character array would be like:
char Bones[9][50];

This is declaring 9 50 element character arrays.
Bones[0] is a char pointer to the first 50 element character array.

strncpy( Bones[0], whatever, whatever );
would copy whatever into the first char array.
Sep 11 '06 #2
Ahhh... ok. On a second look...now I see how this isn't so bad. I'm
pretty I just the library functions and go from there. I think I got it
now. Thanks for the help though.

Jim Langston wrote:
"c++dummy" <ru***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I got this project for my class and I'm totally lost as to how to copy
the 1d array with the bone name into a 2d array using this supposed
strncpy function I'm supposed to create. I believe the teacher wants us
to make the function and not use the library function.

Here's the info:

Write a C++ program that
Opens the file for input using the ifstream facility (see example
program from class).
Declares a two dimensional character array to store the bones from the
input file.
Reads each line of the file and stores the bone in the array position
indicated by the number at the start of the line (e.g., toe is the
first element, foot is the second, etc.; remember that C++ array
indices start with 0). As you process the file, read each bone into a
separate character array and then use the strncpy() function you will
write (see below) to copy the bone name into the main array.
Loops through the main bone array and builds up a long character string
saying which bone is connected to which (e.g., "The toe bone is
connected to the foot bone\nThe foot bone is connected to the ....").
The string should contain a newline character separating each statement
of connectedness. To do this, use the strcat() function you will write
(see below).
Prints the long character string of connectedness to the console.
Your program will use following three functions that you will write.
These functions should use pointer arithmetic rather than array
notation.

void strncpy(char *dest, char *src, int numchr);
Copies the string pointed to by src to the character array pointed to
by dest. numchr is the number of characters to copy. After the copy
operation, dest should be null terminated.

int strlen(char *str)
returns the number of characters in the null-terminated string pointed
to by str.

void strcat(char *dest, char *src)
appends the null-terminated string pointed to by src to the
null-terminated string pointed to by dest. Moves dest's terminating
null to the end of the new string.

Hints:

When you call strncpy, you can use strlen to determine the length of
src
Make sure you make your character arrays big enough
AND HERE IS THE TEXT FILE CONTENT BEING READ:

2 foot
4 leg
10 head
3 ankle
6 thigh
7 hip
1 toe
5 knee
8 back
9 neck

A 2 dimentional character array would be like:
char Bones[9][50];

This is declaring 9 50 element character arrays.
Bones[0] is a char pointer to the first 50 element character array.

strncpy( Bones[0], whatever, whatever );
would copy whatever into the first char array.
Sep 11 '06 #3
On 10 Sep 2006 17:06:59 -0700 in comp.lang.c++, "c++dummy"
<ru***********@gmail.comwrote,
>I got this project for my class and I'm totally lost as to how to copy
the 1d array with the bone name into a 2d array using this supposed
strncpy function I'm supposed to create.
A 2d array is just an 1d array who's elements are more 1d arrays.
(This is even more true in C++ than it is in general.)

So, if you have an array
char foo[10][10]

the one row of it, foo[x], is an array of char that can be passed as
an argument to your function expecting a 1d array of char.

To get the best help, Post The Code that you have written and ask
very specific questions about it. This issue is covered in Marshall
Cline's C++ FAQ. It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

See the welcome message posted twice per week in comp.lang.c++ under
the subject "Welcome to comp.lang.c++! Read this first." or
available at http://www.slack.net/~shiva/welcome.txt

Sep 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1998
by: Neo Chou | last post by:
Greetings! I have a question about constant. I have a page like: ---------------------------------------------------------------------- <% Const adInteger = 3 'copied from adovbs.inc Const...
0
2061
by: Al Caponi | last post by:
Hi all, There is a limitation on Win98 when a client app using mm.mysql driver doing extensive queries to MySQL 3.23.x frequently encounters a connection lost error. Error msg is something...
1
2584
by: News Server | last post by:
Any help appreciated. I have two Access tables, customer and orders. I would like to create a truly hierarchical xml file form the joined tables. I need to produce: <Query1> <Customer>...
1
6676
by: TJRobertsJob | last post by:
Was wondering if someone could help. Over the last month I've been developing a small database application, using Access 2000, for use in a friends shop. Everything was going well until about a...
23
2252
by: Alvin | last post by:
Well, I'm developing a Tetris game in SDL, but when it comes to deciding the next block, I'm stuck. It's random, but when I try something like seeding the randomizer with the time, it won't update...
8
3137
by: CM | last post by:
Hi, Could anyone please help me? I am completing my Master's Degree and need to reproduce a Webpage in Word. Aspects of the page are lost and some of the text goes. I would really appreciate it....
2
4226
by: maxkumar | last post by:
Hi, I am running a ASP.NET 1.1 site on Win Server 2003 with IIS 6.0. The website has been running for about 1.5 years now. In the past, we used to have random cases of session variables getting...
39
3259
by: jacob navia | last post by:
Mnemonic means trying to remember. Mnemonic means making annotations that remind you. Speaking about mnemonic I saw this message. Tor Rustad wrote: One of the problems with old people is...
114
3788
by: Andy | last post by:
Dear Python dev community, I'm CTO at a small software company that makes music visualization software (you can check us out at www.soundspectrum.com). About two years ago we went with decision...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.