compile error

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
dmc
New poster
Posts: 5
Joined: Mon Dec 19, 2005 7:05 pm

compile error

Post by dmc »

please help! I have a compile error!!!
I have used gcc 2.95.2 on my machine and all is OK!

code :

#include <stdio.h>
#include <string.h>
#include <STDLIB.H>
#include <conio.h>

int lasttype = 0; // flag, which previous switch has been executed UP or DOWN
int nqty = 0;
int nPrev = 0;
int qty = 0;
int nValue = 0;
char* tokenptr;
char chSeqarr[256]; // input string
int secchngdUP;
int secchngdDOWN;

int testSequence(int nPrev, int &nUPqty, int &nDOWNqty, int &nUPavgqty, int &nDOWNavgqty, int &nUPlength, int &nDOWNlength );

int main( ) {

int nUPqty = 0;
int nDOWNqty = 0;
int nUPlength = 0;
int nDOWNlength = 0;
int nDOWNavgqty = 0;
int nUPavgqty = 0;

float nUPavg = 0.0;
float nDOWNavg = 0.0;
//clrscr();
printf( "\n Enter sequence: " );
gets(chSeqarr);
// scanf("%s", chSeqarr);
// printf( "\n sequence - : %s ", chSeqarr);
// if (strlen(chSeqarr)==0) return 0;
// printf( "\n sequence - : %s ", chSeqarr);

int result = testSequence(0, nUPqty, nDOWNqty, nUPavgqty, nDOWNavgqty, nUPlength, nDOWNlength );
if (result==1) {
if (nUPavgqty>0) nUPavg = (float)nUPlength / nUPavgqty;
if (nDOWNavgqty>0) nDOWNavg = (float)nDOWNlength / nDOWNavgqty;
printf( "\nNr values: %i %f %f", qty, nUPavg, nDOWNavg );
}
return 1;
}

int testSequence(int nPrev, int &nUPqty, int &nDOWNqty, int &nUPavgqty, int &nDOWNavgqty, int &nUPlength, int &nDOWNlength ) {
if (qty > 30 ) return 0; // max quantity of values is 30
if (strlen(chSeqarr)==0) return 0;

// strtok delimits the values by delimiter (blank)
// this is 1-st step, define previouse value
if (nPrev==0) {
tokenptr = strtok(chSeqarr, " ");
if (*tokenptr=='0') return 0;
nPrev = atoi(tokenptr);
if (nPrev==0) return 0;
qty++;
testSequence(nPrev, nUPqty, nDOWNqty, nUPavgqty, nDOWNavgqty, nUPlength, nDOWNlength );
} else {
// process each value delimited by blank
tokenptr = strtok(NULL, " ");
// terminate program if last value is 0 (*tokenptr)
if ((tokenptr==NULL)||(*tokenptr=='0')) {
if (nUPqty>0) {
nUPavgqty ++;
nUPlength += nUPqty + nqty;
} else {
if ((secchngdUP==0)) {
nUPavgqty = 0;
nUPlength = 0;
}
}
if (nDOWNqty>0) {
nDOWNavgqty ++;
nDOWNlength += nDOWNqty + nqty;
} else {
if (secchngdDOWN==0) {
nDOWNavgqty = 0;
nDOWNlength = 0;
}
}
return 1;
}
nValue = atoi(tokenptr);
// atoi returns zero (0) if can't convert to integer
if (nValue==0) return 0;
qty ++;
if (nValue>nPrev) {
secchngdUP = 1;
lasttype = 1;
nUPqty++;
nUPqty += nqty;
nqty = 0;
lasttype = 1;
if (nDOWNqty>0) {
nDOWNavgqty ++;
nDOWNlength += nDOWNqty;
nDOWNqty = 0;
}
} else {
if (nValue<nPrev) {
lasttype = 2;
secchngdDOWN = 1;
nDOWNqty++;
nDOWNqty+=nqty;
nqty = 0;
if (nUPqty>0) {
nUPavgqty ++;
nUPlength += nUPqty;
nUPqty = 0;
}
} else {
nqty++;
if (lasttype==1) { nUPqty+=nqty; nqty=0;} // change length only for prev. UP sec.
if (lasttype==2) { nDOWNqty+=nqty; nqty=0;} // change length only for prev. DOWN sec.
}
}
nPrev=nValue;
testSequence(nPrev, nUPqty, nDOWNqty, nUPavgqty, nDOWNavgqty, nUPlength, nDOWNlength );
}
return 1;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

#include <STDLIB.H>
There's no STDLIB.H under Unix'es, but there is stdlib.h.
#include <conio.h>
This file is not standard.

Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Re: compile error

Post by Krzysztof Duleba »

dmc wrote:please help! I have a compile error!!!
I have used gcc 2.95.2 on my machine and all is OK!
Have you? Then what's #include <conio.h> doing there?

Anyway, there's no reason to scream and this is not the right forum to ask such questions.

dmc
New poster
Posts: 5
Joined: Mon Dec 19, 2005 7:05 pm

Re: compile error

Post by dmc »

Krzysztof Duleba wrote:
dmc wrote:please help! I have a compile error!!!
I have used gcc 2.95.2 on my machine and all is OK!
Have you? Then what's #include <conio.h> doing there?

Anyway, there's no reason to scream and this is not the right forum to ask such questions.
thanks for all! And sorry for 'scream' :oops:

Post Reply

Return to “C”