-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
typedef struct {int key; int digit; int string[2];}person;
-
//int pass(man a[]);
-
-
-
int main() {
-
-
int apo;
-
int x;
-
-
-
int digit_length = 3;
-
-
double max = 4;
-
-
FILE *fp;
-
-
int store = 1000000;
-
-
person *txPtr;
-
if( (txPtr = calloc( store, sizeof(person) )) == NULL) {
-
-
printf("txPtr:Insufficient memory\n");
-
abort();
-
-
} else {
-
printf("txPtr:Sufficient Memory\n");
-
memset(txPtr,0,sizeof(txPtr));
-
}
-
person *rxPtr;
-
if( (rxPtr = calloc( store, sizeof(person) )) == NULL) {
-
-
printf("rxPtr:Insufficient memory\n");
-
abort();
-
-
} else {
-
printf("rxPtr:Sufficient Memory\n");
-
memset(rxPtr,0,sizeof(rxPtr));
-
}
-
-
-
int y;
-
int ao = 0;
-
-
int key = 1;
-
char name[24];
-
int digit;
-
int z;
-
-
char start[24];
-
int ad = 0;
-
int outputl = 0;
-
char buffer[24];
-
int xyz;
-
for(x = 0; x < max; x++) {
-
txPtr[x].key = x+1;
-
txPtr[x].digit = 1;
-
for(xyz = 0; xyz < digit_length; xyz++){
-
txPtr[x].string[xyz] = 0;
-
}
-
txPtr[x].string[0] = x+1;
-
}
-
-
-
-
-
-
if (( fp = fopen( "unique2.db", "wt" )) == NULL){
-
perror( "Error opening data file\n" );
-
return -1;
-
}
-
-
int digital = 0;
-
int digitstore[digit_length];
-
int zyx;
-
-
-
for(x = key; x < max; x++) {
-
printf("\nOne\n");
-
y = 0;
-
key = txPtr[y].key;
-
digit = txPtr[y].digit;
-
memset(rxPtr,0,sizeof(rxPtr));
-
for(xyz = 0; xyz < digit_length; xyz++) {
-
digitstore[xyz] = txPtr[y].string[xyz];
-
}
-
-
while(!key == 0) {
-
digit = digit + 1;
-
for( z = key; z < max; z++ ) {
-
ad = z+1;
-
rxPtr[ao].key = ad;
-
rxPtr[ao].digit = digit;
-
-
for(xyz = 0; xyz < digit_length; xyz++) {
-
if (xyz == digit - 1) {
-
rxPtr[ao].string[xyz] = ad;
-
} else {
-
rxPtr[ao].string[xyz] = digitstore[xyz];
-
}
-
}
-
-
-
-
-
for(xyz = digit; xyz < digit_length; xyz++){
-
for(zyx = xyz; zyx < digit_length; zyx++) {
-
printf("%d",rxPtr[ao].string[xyz]);
-
}
-
}
-
printf(" Key:%d, z: %d, Digit: %d,String:%d %d %d\n",ad,z,digit,rxPtr[ao].string[0],rxPtr[ao].string[1],rxPtr[ao].string[2]);
-
if(digit == digit_length) {
-
fwrite(rxPtr[ao].string, sizeof(rxPtr[ao].string),1,fp);
-
}
-
ao++;
-
if(digit > digit_length) {
-
printf("\nExceeded digit limit.\n");
-
printf("\nFreeing Memory\n\n");
-
free(txPtr);
-
free(rxPtr);
-
abort();
-
}
-
}
-
y++;
-
key = txPtr[y].key;
-
digit = txPtr[y].digit;
-
-
for(xyz = 0; xyz < digit_length; xyz++) {
-
digitstore[xyz] = txPtr[y].string[xyz];
-
}
-
-
}
-
printf("Mem cop");
-
memset(txPtr, 0, sizeof(txPtr));
-
memcpy(txPtr, rxPtr, store);
-
memset(rxPtr, 0, sizeof(rxPtr));
-
ao = 0;
-
}
-
-
free(txPtr);
-
free(rxPtr);
-
-
if ( fclose(fp) != 0)
-
{
-
fprintf(stderr, "Error closing file.\n");
-
return -2;
-
}
-
return 0;
-
}
-
2 1359
Hi,
I have writtten this C script to produce a series of numbers. However, it seems there is an overflow somewhere and a storage buffer is being filled when it should not be filled.
The output is controlled by the variables DIGIT_LENGTH and MAX
Where DIGIT_LENGTH is the number of digits in a sequence and MAX is how high to count these digits in a sequence.
For example, DIGIT_LENGTH = 3;
and MAX = 3;
This outputs
12
13
23
123
But in this version of the program there are trailing numbers in the sequence...
122
132
233
123
Something like that -
Where are the rxPtr[ao].string[2] getting filled on or before the first pass?
Have you stepped though this with your debugger??
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tony Clarke |
last post by:
Hi,
I'm trying to write a system thats used for about 50 clients that uses html
forms and php to log details. The problem is that when a client loads the
form page it's given a value which is...
|
by: Put 030516 in email subj to get thru |
last post by:
I'm trying to learn about Java MIDI programming. Specifically, I'm
interested in playing with Java MIDI sequencers (all puns intended).
I'm looking at...
|
by: Joe Wong |
last post by:
Hi,
I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this?
Thanks...
|
by: Agoston Bejo |
last post by:
I want to enforce such a constraint on a column that would ensure that the
values be all unique, but this wouldn't apply to NULL values. (I.e. there
may be more than one NULL value in the column.)...
|
by: UJ |
last post by:
Is there any number I can get that is truly unique for a computer that can't
be changed? I want to have a system whereby I have a computer that accesses
a web service based on some unique value...
|
by: Stanley Sinclair |
last post by:
I have a medical records database. At this moment one server.
Providence willing, and if things go well for me, I may have 9 other
servers join in.
Each patient will have, by GENERATE_UNIQUE(),...
|
by: D. Dante Lorenso |
last post by:
I'm trying to build a table that will store a history of records
by enumerating the records. I want the newest record to always
be number ZERO, so I created a trigger on my table to handle the...
|
by: pstachy |
last post by:
Hi again!
I have another issue. I would like the attribute of the tag <invoice>
to be unique. Made the following schema but unfortunately it doesn't
validate. Could someone please indicate what is...
|
by: Marc |
last post by:
Hi all,
I have to generate and send to a printer many 6 digit
alphanumeric strings. they have to be unique but I cannot check in a
database or something like that if it have already been printed....
|
by: dez5000 |
last post by:
I'm trying to get a report by location that would list the number of visits to the location for the month but also count the number of unique visitors to that location.
I have a table of data with...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |