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

7
  • 1
    If this isn't homework, then why would you bother doing this? Commented Oct 28, 2011 at 0:13
  • See also: stackoverflow.com/questions/7537874/… Commented Oct 28, 2011 at 0: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). Commented Oct 28, 2011 at 0:18
  • 1
    with the HTML stripped out, it compiles and runs as expected for me. Commented Oct 28, 2011 at 0:19
  • If you're interested in implementing int to string formatting, have a gander at my question here: stackoverflow.com/questions/4351371/… Commented Oct 28, 2011 at 0:24

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.