i'm using a windows XP.
Here's my code, but most of it is extraneous to my question. I am concerned with the section highlighted in red.
Edit : i realize that red is an eyesore, but so are all the other colors!!!!!!;
As you can see, I have various commented out code segments or debugging printf's. these are labeled in blue for future reference.Code:#define true (char)1; #define false '\0' #define GEN struct generation typedef unsigned char boolean; struct {int* list; int length;} numList; struct coordinates {int x; int y;} pos; struct generation {boolean val; struct generation *next;}; int data[128]; int special=0,superspec=0; void check(int); void freeList(GEN*); #include <random.h> #include <random.c> #include <stdio.h> //int CRAP = 43; //#undef NULL //#define NULL &CRAP void main() { static unsigned int arr[128]; int i; for (i=0; i < 128; i++) arr[i] = i; numList.list = arr; //printf("%d\n\n\n\n",sizeof(int)); 1 numList.length = 128; for (i=0; i < 128; i++) { int j; data[i] = getRand(0, numList.length-1); check(data[i]); numList.length=numList.length-1; for (j=data[i]; j < numList.length; j++) numList.list[j] = numList.list[j+1]; } getchar(); } void freeList(GEN *gen) { if (gen->next != NULL && gen->next != gen) freeList(gen->next); special |= ((int)gen->val?1:0)<<superspec++; free(gen); } void check(int in) { GEN *root; int out = in + 1; int x, cur = 0, i; unsigned int y; boolean prev = false; GEN *last, *end; root->next = root; root->val = false; last->val = end->val = root->val; last->next = end->next = root->next; for (i = 0; i < sizeof(int)*8 && in/(1<<i); i++) { GEN *nNode; //printf("1dog\n"); 2 nNode=(GEN*)malloc(sizeof(*nNode)); //printf("2dog\n"); 3 if (nNode == NULL) exit(0); nNode->next = last; //printf("3dog\n"); 4 nNode->val = (1<<i) & in; //printf("4dog\n"); 5 last = nNode; //printf("5dog\n"); 6 } x=i; //printf("%d\n",x); 7 end->next = last; //freeList(end); 8 printf("%d\n",special); 9 getchar(); exit(0); while (cur != out) { int t=x; prev = false; last->val = end->val = true; last->next = end->next = end; while (x-- > -sizeof(int)) { boolean temp=prev, next=last->next->next->val; cur = (cur<<1) | ( (int)last->next->val?1:0 ); prev = last->next->val; last = last->next; if (last!=root) { if ( temp && prev && next || !(temp || prev || next) || temp && !(prev || next) ) last->val = false; else last->val = true; } if (cur == out) goto finish; } y++; x = t+1; } finish: while (last != root) { boolean temp=prev, next=last->next->next->val; prev = last->next->val; last = last->next; if ( temp && prev && next || !(temp || prev || next) || temp && !(prev || next) ) last->val = false; else last->val = true; } pos.x = x; pos.y = y; printf("%d+1==%d at (%d, %d)\n", in, out, x, y); }
All red printf's are meant for debugging purposes.
depending on the value of "special" and which of the different blue-labeled code segments i have enabled (as in not commented out) i get radically different output. the number of newlines in segment 1 can determine what value is printed in segment 9 or whether my program terminates prematurely, and sometimes segment9 has printed stuff to the screen and then the program blocked, without accepting input (that is, if i typed a letter, it would not appear on the screen, and typing a letter and pressing enter would not terminate the program).
the "dog" printf's (segments 2 thru 6) always worked fine, as did segment 1. calling segment 8 can yield weirder or more normal output, depending on the situation. there have been times when my cursor was placed in already-printed text, so that by typing a letter i would overwrite stuff that had already been printed out by the program.
depending on different combinations of enabled segments, i have gotten outputs that varied somewhat from execution to execution (tho still followed some patterns) and outputs that were senseless but were the same every execution. printing out stuff before the weirdness happens seems to (in general) make the weird stuff less weird (and more concise).
the value of special, when it is distinguishably printed out, is either 1, 2, -255, or -254, depending on the value i initialize it to and on the number of printf's in segment 1.
now, finally for some sample output:
M ╙}
♠2♦■±↕☺ ∞ ¶╨♥|♥ ¶Σ☺▬■¶◄1 Γ☺╨♥|♥ ╩..H 1 Γ☺ ☻ ☺% ╢.. ↕¡↕tEΦ
....☺ ....☺ ☺ {♥
!5|► òC┤d╨.. ' ♦ ─..IB¡1 ╬dw3← '
∞B╨..╘..░☺Γ☺▄..ε..ù☺☺ α..á↨ ∞☺..♠ ♠ 6 ∞☺°..
the above is one of the most common (and one of my favorites!). it is produced by the code above. it retains this format and many of the early and middle characters, but the latter characters differ somewhat for each execution.
I just noticed that when i executed this in command prompt (rather than double clicking it in my computer) the directory is subsequently altered.
...
C:\DOCUME~1\Nick\MYDOCU~1\C>dd
'dd' is not recognized as an internal or external command,
operable program or batch file.
C:\DOCUME~1\Nick\MYDOCU~1\C>dd
(it should be c:\documents and settings\nick\my documents\c)
more output...
1
(there is an empty line before the one in the output)
the above out put is just like the code before except that segment 7 has been enabled
in other words, i think my program is altering its own instructions at run time due to inadvertantly overwriting memory in the for loop, but i am too stupid to figure out where my error is :-(
thanks



LinkBack URL
About LinkBacks


