Thread: Creating a mastermind game

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    First off, when posting code, make sure you do either "copy as text" from your IDE, or "paste as text" in your browser.
    Your whacky colour scheme makes a complete mess of the board formatting.

    From the question, it seems you want to replace
    > guessArray[0] = guess / 1000
    with
    Code:
    for ( i = 0 ; i < 4 ; i++ )
      guessArray[i] = ans[i] - '0';
    That is, if you're looking to convert a string "1234" into an array of integers 1,2,3,4
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #2
    Registered User
    Join Date
    Oct 2022
    Posts
    11
    I am having problems with the read function
    "Copy as text from vscode"
    Code:
    char* ans = (char*) malloc(5 * sizeof(char));
    int i = read(0, ans, 5);
    if (i == 0) return;
    while (!isCorect(ans))
        {
    read(0, ans, 5);
        };
    
    
    using this function the answer just keeps loading and loading without end after pressing enter key

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-04-2015, 11:00 AM
  2. c program for the mastermind game
    By College94 in forum C Programming
    Replies: 3
    Last Post: 04-14-2015, 12:09 PM
  3. Again, Mastermind Game Assistant Question
    By Jesterira in forum C Programming
    Replies: 8
    Last Post: 12-07-2012, 06:45 PM
  4. Problem with simple Mastermind game(beginner)
    By newbie2012 in forum Game Programming
    Replies: 1
    Last Post: 11-12-2012, 03:51 AM
  5. Finishing up Mastermind game program
    By Charak in forum C Programming
    Replies: 5
    Last Post: 02-17-2011, 02:49 AM

Tags for this Thread