why does the following not work ?
c==0?continue:break;
There is nothing behind of before it which is affecting the compilation. This is the error:
Quote:xyuri@bsdmachine$ make
g++ -c a1mstrncmp.cpp
g++ -c mstrncmp.cpp
mstrncmp.cpp: In function `int mstrncmp(const char*, const char*, size_t)':
mstrncmp.cpp:29: error: expected primary-expression before "continue"
mstrncmp.cpp:29: error: expected `:' before "continue"
mstrncmp.cpp:29: error: expected primary-expression before "continue"
mstrncmp.cpp:29: error: expected `;' before "continue"
*** Error code 1
Stop in /usr/home/xyuri/code/se93a1.
is it not possible to use break / continue type statements in these things ?
Edit: ok, for the sake of supplying sufficient information here is the whole code ... it is a replacement function for the built in one (strncmp) for an assignment ... this doesnt help me with me assignment because as you can see it is already done and working, i'm just tidying up syntax now like i have done for the other 5 functions we needed to write.
//|
//| mstrlen.cpp
//|
//| Author.: Michael Dawson
//| Date...: 10/03/2006
//|
//| Purpose: .
//|
#include "mstr.h"
//
// Purpose: simulate the effect of strncmp
// function in standard library.
// Pre....: s1 and s2 must be a properly terminated c string.
// Post...: Returned value indicates difference.
//
int mstrncmp(const char *s1, const char *s2, size_t n)
{
int c;
for (int i=0 ; i<n ; i++) {
if (*s1=='\0' || *s2=='\0') break;
c = *s1++ - *s2++;
//if (c == 0) { continue; } else { break; }
c==0?continue:break;
}
return c;
}
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend