473,398 Members | 2,427 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,398 software developers and data experts.

Pointer Help

Anything wrong with this code? I got an error message "user breakpoint called from code at "0x7c901230" after excute the line "delete a", please help.

int main()
{

FILE *fp;
FILE *stream = fopen("ExchID.txt", "w");

if((fp = fopen( "testInput.txt", "r" )) != NULL)
{
char line[128];
int i = 0;
int *a = new int;
int *b = new int;
int *c = new int;
int *d = new int;
int *e = new int;
int *f = new int;

while(fgets(line, 128, fp))
{
if(sscanf(line, "%d, %d, %d, %d, %d, %d", &a[i], &b[i], &c[i], &d[i], &e[i], &f[i]) == 6)
{
fprintf(stream, "I:%d, %d, %d, %d, %d, %d\n",a[i], b[i], c[i], d[i], e[i], f[i]);

dm_exch_delta_clo((DBA_XCHG*)&a[i], (dba_clorg*)&b[i], (DBA_DATE*)&c[i], (SYS_TIME*)&d[i], (short*)&e[i], (unsigned char*)&f[i]);
fprintf(stream, "O:%d, %d, %d, %d, %d, %d\n",a[i], b[i], c[i], d[i], e[i], f[i]);
++i;
}
else
{
assert(0);
}
}
fclose(fp);
fclose(stream);

delete a;
delete b;
delete c;
delete d;
delete e;
}

return 0;
}
Mar 28 '07 #1
4 1299
horace1
1,510 Expert 1GB
a, b, c, etc are arrays so try allocating arrays, e.g.
Expand|Select|Wrap|Line Numbers
  1. int i = 0;
  2. int *a = new int[10];
  3. int *b = new int[10];
  4. int *c = new int[10];
  5. int *d = new int[10];
  6. int *e = new int[10];
  7. int *f = new int[10];
  8.  
Mar 28 '07 #2
gpraghuram
1,275 Expert 1GB
HI,

The real problem in your code was you are allocating only for one block of int, after that you are incrementing the block using ++i.
You can follow any one of these methods to solve the problem
1)For the elements a,b etc allocate using malloc or try to use it as a array like int a[<size u require>].
2)instead of using pointer or array for a u can declare as int a. and then pass the address of it to the sscanf funtion

Thanks
Raghuram
Mar 29 '07 #3
Thanks guys.
Mar 29 '07 #4
Ganon11
3,652 Expert 2GB
Just a message to let you know I've changed the title to be a bit more descriptive.
Mar 29 '07 #5

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

Similar topics

5
by: ali | last post by:
Hi, I'm trying to understand the reason for different output on the following codes Code1: #include <iostream.h> int main()
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
10
by: Simon | last post by:
I'm a js newbie trying to use some very simple js to call an ActiveX object's methods. I need to use a pointer to call an embedded ActiveX object's method to receive a number. As I understand it,...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
6
by: lithiumcat | last post by:
Hi, maybe you remember me, some time ago I asked about how to store an integer value into a void*, and I learned that doing pointer arithmetic yeilding a pointer outside of an object (except the...
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...
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
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
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
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
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
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.