baavgai's Profile User Rating: *****

Reputation: 6052 Overlord
Group:
Mentors
Active Posts:
13,132 (4.83 per day)
Joined:
16-October 07
Profile Views:
130,869
Last Active:
User is offline Today, 05:34 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
725
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: Returning a char pointer

    Posted 25 Mar 2015

    int keylength;
    char* fin = malloc(keylength * sizeof(char));
    keylength = strlen(key);
    
    


    It would help if you load keylength before you allocate based on it.

    It's unclear why you'd need so many copies. Why the double encoding?

    Just for fun:
    char encodeChar(char, char);
    char decodeChar(char, char);
    void vigenere(char *msg, char *key, char *result, int encode);
    
    void test(char *msg, char *key) {
        char *buff = malloc(strlen(msg) + 1);
        printf("Message: %s\n", msg);
        printf("Key: %s\n", key);
    
        vigenere(msg, key, buff, 1);
        printf("Enc 1: %s\n", buff);
        vigenere(buff, key, buff, 1);
        printf("Enc 2: %s\n", buff);
        vigenere(buff, key, buff, 0);
        printf("Dec 1: %s\n", buff);
        vigenere(buff, key, buff, 0);
        printf("Dec 2: %s\n", buff);
        printf("Valid: %s\n", (strcmp(msg,buff)==0)?"True":"False");
    
        free(buff);
    }
    
    int main() {
        test("ABCDE", "ZIGGY");
    
        return 0;
    }
    
    


    Results:
    Message: ABCDE
    Key: ZIGGY
    Enc 1: ZJIJC
    Enc 2: YROPA
    Dec 1: MWVWP
    Dec 2: ABCDE
    Valid: True
    
    


    Note, my vigenere function makes no calls to malloc or the like; no allocations need be made to make it work. If you must have that wonky output, you'll probably need one allocation. Pay attention to how I did it in test; the sizing is important.

    Note, applying the same key twice is non standard. It also gains you nothing; you'll get the same results if you apply the key to itself and then apply it. Which is to say, you just use a single key.

    Hope this helps.
  2. In Topic: Weird loop issue (C)

    Posted 24 Mar 2015

    You have a few things going on here.
    res =(char*)realloc(res,strlen(s));
    /* res does NOT have enough room for s
       you forgot about '\0'
    
    Why strcat instead of strcpy?!?
    If you want to append a string (strcat), 
    then you need an end of string to append to
    when did you set *res to 0?
    */
    strcat(res,s);
    /* actually, you may not even get here
    but if you do, your res doesn't have enough room 
    for a string terminator.
    You might get away with it, once in a while, 
    if nothing else in your program allocates...
    */
    
    


    Hope this helps.
  3. In Topic: 2 dimensional arrays/ Tic tac toe game.

    Posted 22 Mar 2015

    Ok, since lost doesn't even begin to describe this...

    You want a loop. A "game" loop. The players take turns and the loop runs until the game completes, either because someone won or because there are no more moves.

    Here's a simple framework:
    public class TicTacToe {
        public static void main(String[] args) {
            playGame();
        }
    
        public static void playGame() {
            // int n = 4; huh? no.  wtf 4?
            char[][] gameBoard = new char[3][3];
            // s is a horrid name
            // Scanner s = new Scanner(System.in);
            Scanner scanner = new Scanner(System.in);
            // this is pointless
            // Random r = new Random(System.currentTimeMillis());
    
            // why the hell would you return anything?
            // char[][] gb = printArray(gameboard);
    
            // huh?
            // int rand = r.nextInt(2) ;
    
            // right
            //
            // here we'll fill with '?'
            // this is NOT to be confused with printing!!!
            initBoard(gameBoard);
    
            char turn = 'X'; // we start with X
            while(!isGameOver(gameBoard)) {
                // print here
                showBoard(gameBoard);
    
                System.out.println(turn + " it is your turn!");
                System.out.println();
                System.out.println("enter the coordinates of untaken cell in a row colum format");
                System.out.println("ie. 1 0 will place your mark in row 1 column 0 of the grid");
                System.out.println("your entry please...");
                int row = scanner.nextInt();
                int col = scanner.nextInt();
                if (isValid(gameBoard, row, col)) {
                    gameBoard[row][col] = turn;
                    // toggle turn
                    // your code here
                } else {
                    // let them know they entered crap
                    // your code here
                }
            }
            // someone won or it's a tie
            // show final board
            showBoard(gameBoard);
            // show results
            if (isWin(gameBoard,'X')) {
                // your code here
            } else if (isWin(gameBoard,'O')) {
                // your code here
            } else {
                // it's a tie
                // your code here
            }
        }
    }
    
    


    Hope this helps.
  4. In Topic: Return array from function in C

    Posted 21 Mar 2015

    It's a fundamentally awful example. The static is confusing. You should never, ever, use srand outside of main. Returning pointers is usually a questionable activity. The magic number 10 is simply bad.

    For a quick example if the strange world of static:
    #include <stdio.h>
    
    void showStatic() {
        static int x = 0; /* this will only get called once */
        int y = 0; /* this will get called each time showStatic is entered */
        printf("x=%d, y=%d\n", ++x, ++y);
    }
    
    int main () {
        showStatic();
        showStatic();
        showStatic();
        showStatic();
    
        return 0;
    }
    
    


    Results:
    x=1, y=1
    x=2, y=1
    x=3, y=1
    x=4, y=1
    
    
  5. In Topic: help is my ERD and database structure is correct?

    Posted 21 Mar 2015

    The book_name and student_name are redundant, denormalized. They are also not foreign keys. The tbl in the name is also redundant.

    Instead:
    borrowed
      student_id: PK, FK
      book_id: PK, FK
      issued_date
      due_date
    
    

My Information

Member Title:
Dreaming Coder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Jersey, be afraid.
Years Programming:
25
Programming Languages:
Most.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    ImChicago Icon

    17 Mar 2015 - 17:34
    Hey, im new to coding, how do you recommend starting? What should I master first? Should I use a website to help me?
  2. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  3. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  4. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  5. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  6. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  7. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  8. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  9. Photo

    Jeet.in Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
    http://www.dreamincode.net/forums/topic/275578-simple-whitespace-remover/page__gopid__1603556&#entry1603556
  10. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
    http://www.dreamincode.net/forums/topic/252848-venting-a-frustration/page__view__findpost__p__1469659
  11. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  12. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  13. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  14. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  15. Photo

    hulla Icon

    02 Aug 2011 - 02:50
    Wow that's alot of programming languages... :O
  • (3 Pages)
  • +
  • 1
  • 2
  • 3