Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Woohoo simple school assignments

Name: Anonymous 2010-05-03 18:07

Hey there /prog/, you guys seem less than retarded, so I'm asking you for your help. I need to do some palindromes, just single words, but I'm retarded.

Does anyone know why my Sepples codes doesn't work? 'x' isn't set to the right value no matter the input, which throws off the palindrome checking function, which sucks cocks.

Here's the code. Note, I cannot use any str functions.


//Project 14 - Palindromes
#include <iostream>
using namespace std;

int main()
{
    char str[100];
    int x = 0; //Will be the string length
    cout << "Enter a word to see if it's a palindrome: ";
    cin >> str;
    for(int i = 0; i < 100; i++) {
        if (str[i] == '\0') {
            x = i - 1;
        }
    }
    cout << "X = " << x << endl;
    for(int i = 0; i <= x; i++){
        cout << str[i] << "   " << str[x-i] << endl;
        if (str[i] == str[x-i]) {
            continue;
        }
        else {
            cout << "That word is not a palindrome. " << endl;
            return 0;
        }
    }
    cout << "That word is a palindrome!" << endl;
    return 0;
}


Where am I fucking up?

Thanks, I love you /prog/

Name: Anonymous 2010-05-03 18:53

format ELF64

extrn printf
extrn gets

section '.text' executable
public main
main:
    xor eax, eax
    lea edi, [msg]
    call printf

    xor eax, eax
    lea edi, [_str]
    call gets

    xor edi, edi
    lea esi, [_str]
@@:    lodsb
    inc edi
    test al, al
    jnz @b

    dec edi

    lea esi, [_str]
@@:    lodsb
    dec edi
    test al, al
    jz .palin
    cmp al, [_str + edi]
    je @b

.nonpalin:
    xor eax, eax
    lea edi, [nonpalin]
    jmp printf
.palin:
    xor eax, eax
    lea edi, [palin]
    jmp printf

section '.bss' writeable
_str:    times 100 db ' '

section '.data'
msg:    db "Enter a word to see if it's a palindrome: ", 0
palin:    db "It's a palindrome!", 10, 0
nonpalin: db "It's not a palindrome ;_;", 10, 0

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List