0
#include <stdio.h>
//#include <<strong class="highlight">string</strong>.h>

// Function declarations
// typedef __w64 unsigned int size_t
size_t strlen(const char *);
char *strrev(char *);
char *itoa(int, char *, int);

int main() {
    int num = 123;
    char buf[5];

    itoa(num, buf, 10);

    printf("%s\n", buf);

    return 0;
}

size_t strlen(const char *string) {
    const char *s;

    s = <strong class="highlight">string</strong>;
    while (*s)
        s++;
    return s - <strong class="highlight">string</strong>;
}

char *strrev(char *str) {
    char *p1, *p2;

    if (!str || !*str)
        return str;

    for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) {
        *p1 ^= *p2;
        *p2 ^= *p1;
        *p1 ^= *p2;
    }

    return str;
}

char *itoa(int n, char *s, int b) {
    static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
    int i=0, sign;

    if ((sign = n) < 0)
        n = -n;

    do {
        s[i++] = digits[n % b];
    } while ((n /= b) > 0);

    if (sign < 0)
        s[i++] = '-';
    s[i] = '\0';

    return strrev(s);
}

getting error on this part of the question...

s = string; while (*s) s++; return s - string;

saying missing 'class' : missing tag name and syntax error: <

I don't know how to fix it.. trying various stuff..

any help would be appreciated..

thanks alot

sth
  • 222,467
  • 53
  • 283
  • 367
Gagandeep
  • 43
  • 1
  • 8
  • 1
    If this isn't homework, then why would you bother doing this? – Marvo Oct 28 '11 at 00:13
  • See also: http://stackoverflow.com/questions/7537874/how-do-you-convert-an-int-into-a-string-in-c – johnsyweb Oct 28 '11 at 00:15
  • 3
    @RayToal: I think the HTML you just edited out of the question was the cause of the problem (note the `<` in the error message). – Keith Thompson Oct 28 '11 at 00:18
  • 1
    with the HTML stripped out, it compiles and runs as expected for me. – hex4def6 Oct 28 '11 at 00:19
  • If you're interested in implementing int to string formatting, have a gander at my question here: http://stackoverflow.com/questions/4351371/c-performance-challenge-integer-to-stdstring-conversion – Ben Voigt Oct 28 '11 at 00:24
  • Addendum: Think I found the source of this code:http://www.daniweb.com/software-development/c/threads/11049 – hex4def6 Oct 28 '11 at 00:24
  • Woops. Sorry about the edit. I see now the OP could have copy/pasted bad code from somewhere else. That would never happen with SO's awesome editor! – Ray Toal Oct 28 '11 at 01:14

1 Answers1

3

It looks like you've somehow gotten HTML markup into your C++ source code:

s = <strong class="highlight">string</strong>;
while (*s)
    s++;
return s - <strong class="highlight">string</strong>;

I would have gone ahead and fixed it, but the error message refers to a < character, so I think that's your actual problem. Perhaps you incorrectly copy-and-pasted the code from some web page?

EDIT: I see @RayToal has edited the HTML out of your question.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • I tested it and you get the errors mentioned in the question when you try to compile the code including the HTML markup. So you are most likely right that this is the problem. – sth Oct 28 '11 at 00:22