473,396 Members | 1,866 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.

error when passing value to function

Hi,

Just wanted to ask if anybody has any idea what i'm doing wrong.

I have a function which edits a linked list. It works fine.
I pass in a pointer to the list plus the value of the item to be
edited.

The value to be edited is a string which has been converted to an int
using atoi.
It is converted fine, then I pass this value to the function and when
I try to access the LL values I get an access violation error.

I debugged the code and I cannot figure out what's going wrong.

I also tried converting the string to an int in the same way, within
the edit function and this works fine.

Has anyone experienced this before??

Thanks in advance,
Ritchie.

/***************************code******************* ******/
-----------------------------------------
Function call in main --
editList( &nStart, convertDate( ) );
(value returned is correct)
-----------------------------------------

int convert( ) /*takes input as string & converts to int */
{
char sYear[1], sMonth[1], sDay[1], sFullDate[9]="";
int iFullDate=0;

printf("Enter day (dd): "); scanf("%s", sDay);
printf("Enter month (mm): "); scanf("%s", sMonth);
printf("Enter year (yyyy): "); scanf("%s", sYear);

strcat(sFullDate, sYear);
strcat(sFullDate, sMonth);
strcat(sFullDate, sDay);

/*convert full date to int*/
return iFullDate = atoi(sFullDate);
}

/*-------------------edit-------------------------------*/
void edit( NodePtr *sPtr, int iData)
{
NodePtr prevPtr, currPtr;

if( iData == (*sPtr)->iOrderDate.iFullDate ) /*THIS IS WHERE I GET
ERROR*/
{
printf("Account found > ");
...
...
...
/************************************************** *******/
Nov 14 '05 #1
2 1468
On 22 Feb 2004 09:25:20 -0800, ri*********@yahoo.com (ritchie) wrote:
Hi,

Just wanted to ask if anybody has any idea what i'm doing wrong.

I have a function which edits a linked list. It works fine.
I pass in a pointer to the list plus the value of the item to be
edited.

The value to be edited is a string which has been converted to an int
using atoi.
It is converted fine, then I pass this value to the function and when
I try to access the LL values I get an access violation error.

I debugged the code and I cannot figure out what's going wrong.
What do you mean by "debugged"? If you have an IDE that shows the value of
your data, and you looked at the contents of sYear, sMonth and sDay as you
were stepping through the first part of convert(), the problem should have
been pretty obvious...

I also tried converting the string to an int in the same way, within
the edit function and this works fine.
My /guess/ is that you did them one at a time (scanf, convert, scanf,
convert, scanf convert), right? You might have gotten away with that, if
you were unlucky ;-)
Has anyone experienced this before??
Buffer overruns? Yup, at least once or twice ;-)

You've sized your buffers as ONE-element char arrays. That means they each
have room for their terminating NUL, and nothing else. To make this work
more-or-less the way you intend, make those buffers bigger. If you really
want a robust app, throw away everything you've done for the input routine
and start over using functions you can sanity-check along the way. For
example, you might consider having the user enter all the data into one
char buffer (using, say, fgets), then using sscanf to convert all the
values at once and validate that they were provided. After that, you can
check the values to be valid for what they represent, of course, as well.
-leor
Thanks in advance,
Ritchie.

/***************************code******************* ******/
-----------------------------------------
Function call in main --
editList( &nStart, convertDate( ) );
(value returned is correct)
-----------------------------------------

int convert( ) /*takes input as string & converts to int */
{
char sYear[1], sMonth[1], sDay[1], sFullDate[9]="";
int iFullDate=0;

printf("Enter day (dd): "); scanf("%s", sDay);
printf("Enter month (mm): "); scanf("%s", sMonth);
printf("Enter year (yyyy): "); scanf("%s", sYear);

strcat(sFullDate, sYear);
strcat(sFullDate, sMonth);
strcat(sFullDate, sDay);

/*convert full date to int*/
return iFullDate = atoi(sFullDate);
}

/*-------------------edit-------------------------------*/
void edit( NodePtr *sPtr, int iData)
{
NodePtr prevPtr, currPtr;

if( iData == (*sPtr)->iOrderDate.iFullDate ) /*THIS IS WHERE I GET
ERROR*/
{
printf("Account found > ");
...
...
...
/************************************************** *******/


Leor Zolman
BD Software
le**@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #2
On 22 Feb 2004 09:25:20 -0800, ri*********@yahoo.com (ritchie) wrote:
Hi,

Just wanted to ask if anybody has any idea what i'm doing wrong.

I have a function which edits a linked list. It works fine.
I pass in a pointer to the list plus the value of the item to be
edited.

The value to be edited is a string which has been converted to an int
using atoi.
It is converted fine, then I pass this value to the function and when
I try to access the LL values I get an access violation error.

I debugged the code and I cannot figure out what's going wrong.

I also tried converting the string to an int in the same way, within
the edit function and this works fine.

Has anyone experienced this before??

Thanks in advance,
Ritchie.

/***************************code******************* ******/
-----------------------------------------
Function call in main --
editList( &nStart, convertDate( ) );
(value returned is correct)
Where is the function editList defined?
-----------------------------------------

int convert( ) /*takes input as string & converts to int */
{
char sYear[1], sMonth[1], sDay[1], sFullDate[9]="";
int iFullDate=0;

printf("Enter day (dd): "); scanf("%s", sDay);
printf("Enter month (mm): "); scanf("%s", sMonth);
printf("Enter year (yyyy): "); scanf("%s", sYear);
Each of these invokes undefined behavior due to overflow of the
destination arrays.

strcat(sFullDate, sYear);
strcat(sFullDate, sMonth);
strcat(sFullDate, sDay);

/*convert full date to int*/
return iFullDate = atoi(sFullDate);
}

/*-------------------edit-------------------------------*/
void edit( NodePtr *sPtr, int iData)
{
NodePtr prevPtr, currPtr;

if( iData == (*sPtr)->iOrderDate.iFullDate ) /*THIS IS WHERE I GET
ERROR*/
What does *sPtr evaluate to? Is it possibly NULL? Since you don't
show the call to this function, it is a little difficult to say what
is wrong.
{
printf("Account found > ");
...
...
...
/************************************************** *******/


<<Remove the del for email>>
Nov 14 '05 #3

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

Similar topics

6
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
1
by: soup_or_power | last post by:
I'm passing the return from window.open as a function argument and getting the error "missing ] after element list" when tested with FireFox. Here is the relevant code. Many thanks for your help....
12
by: Neil Dunn | last post by:
Hi, I don't seem to be able to get asprintf to work when compiling under OS X. Using the following code: #include <string.h> #include <stdio.h>
9
by: Tyler | last post by:
I am attempting to extend a legacy VB6 application by making it use a .NET component written in C# exposed through COM interop. Everything appeared to be going well (VB application creates the...
9
by: VancouverMike | last post by:
Hi there, I run into a very strange problem. I got the following url and am passing information via query string. The problem when the "sin" key in query string is blank, shown as in the...
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
21
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
9
by: Finger.Octopus | last post by:
I dont know whats terribly going wrong with this, well I know there's some memory allocation with this but I tried hard to fix it and when it gets fixed it doesn't shows up the desired value, this...
6
by: cleary1981 | last post by:
I have adapted code from http://dunnbypaul.net/js_mouse/ I want to use a button to create new draggable divs but i keep getting error "is null or not an object" heres the code <html> <head>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.