473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

function quick question

11
Re: expected primary-expression error
--------------------------------------------------------------------------------

void setName(char newFirst[], char newLast[])
This function will change either first name, last name, or both. If the "null string" is passed for either argument, the corresponding data member will not be altered. No error checking need be done.
The null string can be supplied by passing the string literal "" to the function (that is, two double-quote chars with no space between them) or by supplying a char array with '\0' in ar[0].

oh! and if i have a functiont that must do this, is this right?
void Student::setName(char newFirstname[], char newLastname[])
{
strcpy(lastname, newLastname);
strcpy(firstname, newFirstname);

}
May 2 '07 #1
1 1025
weaknessforcats
9,208 Expert Mod 8TB
Nope.
Expand|Select|Wrap|Line Numbers
  1. strcpy(lastname, newLastname);
  2.  
Here strcpy() will copy from newLastname to lastname until a \0 is reached in newLastName. If lastname is "Wolf" and newLastName is "Little Red Riding Hood", strcpy() will overstore memory beyond "Wolf" creating a corruption that will result in a crash.

You can never copy into a target location unless you are certain there is enough memory at the target location to hold the new contents. A secondary problem is what to do woth the contents at the target that you are overriding.

Plus, you say that lastname will not be changed if newLastName is "" but your code does the copy anyway. lastname is now "" and violates your spec. I see no test for "" to bypass the copy to lastname.

Ditto for firstname.
May 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ¤ Alias | last post by:
I have a function named getID3info (lvwDiscInfo.SelectedItem). What is the difference between getID3info (lvwDiscInfo.SelectedItem) and Call getID3info(lvwDiscInfo.SelectedItem) ?
7
by: kdc | last post by:
Hello, I would appreciate any help I can get from anyone who has experience using javascript. I have an html form containing a number of functions controlling the submission of data to our...
4
by: Mike Reid | last post by:
Appreciate any feedback on the MOD function. I am at a loss to understand its "mathmatics". From the help Result = Number1 MOD Number2 where the result should be the remainder of the...
13
by: dimitris67 | last post by:
How can I replace an occurence of p(a string) in an other string(s) with np(new string).. char* replace _pattern(char *s,char *p,char *np) PLEASE HELP ME!!!!!
9
by: Kishor | last post by:
Hi all, I am Using VB.Net for developing my application. I am now needed help. In this project I have to execute some function, but I cannot call them directly using function name, I wanted to...
12
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int...
10
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion...
4
by: bvdp | last post by:
Terry Reedy wrote: <snip> <snip> <snip>
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
6
by: Andrus | last post by:
I need to implement vfp function which uses * and ? wildcards: static bool Like( cExpression1, cExpression2) cExpression1 Specifies the character expression that Like( ) compares with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.