Computer Science Canada

Array of pointers

Author:  Tubs [ Wed Nov 16, 2005 11:47 pm ]
Post subject:  Array of pointers

Is the best way to change a array belonging to the main function inside a different function by using enumerated types & a pointer to it?

Author:  wtd [ Thu Nov 17, 2005 12:02 am ]
Post subject: 

Well, you have an array declared inside your main function.

c:
int main()
{
   int foo[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

   return 0;
}


What you really have is a glorified pointer that points to the beginning of the array.

This pointer can be passed to another function. But, since you just have a glorified pointer, no information about the length of the array gets passed with it. So we have a separate parameter for the length of the array.

Then inside the function, we can iterate over the array.

c:
void increment_all(int *input_array, int size_of_array)
{
   int index;

   for (index = 0; index < size_of_array; index++)
   {
      input_array[index]++;
   }
}


And back in main we can use that.

c:
#include <stdio.h>

void increment_all(int *input_array, int size_of_array)
{
   int index;

   for (index = 0; index < size_of_array; index++)
   {
      input_array[index]++;
   }
}

int main()
{
   int index;
   int foo[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

   increment_all(foo, 10);

   for (index = 0; index < 10; index++)
   {
      printf("%d\n", foo[index]);
   }

   return 0;
}

Author:  Tubs [ Thu Nov 17, 2005 12:24 am ]
Post subject: 

I should have been more specific. How about multi dementional arrays? (2 in the case I am working with)

Author:  wtd [ Thu Nov 17, 2005 12:58 am ]
Post subject: 

Ok. A two-dimensional array is an array of arrays. Each of those arrays is a pointer to its beginning. Thus the two-dimensional array is just a glorified pointer to a glorified pointer.

However, there is a complication. If we have a multidimensional array, we cannot pass declare the function as taking a pointer to a pointer.

Here's some working code to consider:

c:
#include <stdio.h>

void increment_all(int (*input_array)[5], int y_dimension)
{
   int x_index, y_index;

   for (y_index = 0; y_index < y_dimension; y_index++)
   {
      for (x_index = 0; x_index < 5; x_index++)
      {
         input_array[y_index][x_index]++;
      }
   }
}

int main()
{
   int x_index, y_index;
   int foo[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};

   increment_all(foo, 2);

   for (y_index = 0; y_index < 2; y_index++)
   {
      for (x_index = 0; x_index < 5; x_index++)
      {
         printf("%d\n", foo[y_index][x_index]);
      }
   }

   return 0;
}

Author:  Tubs [ Thu Nov 17, 2005 1:07 am ]
Post subject: 

Isn't C silly. You rock my socks wtd.

Author:  wtd [ Thu Nov 17, 2005 1:13 am ]
Post subject: 

Tubs wrote:
Isn't C silly.


Yes.

Tubs wrote:
You rock my socks wtd.


Glad to help.

Thank you for asking a relatively focused question. These are so much easier to approach than, "here's my hundred lines of code... what's wrong?!"

Smile

Author:  wtd [ Thu Nov 17, 2005 1:19 am ]
Post subject: 

Yes, C is silly. Fortunately there are other fish in the sea.

code:
# let foo = [|[|1; 2; 3|]; [|4; 5; 6; 7|]|];;
val foo : int array array = [|[|1; 2; 3|]; [|4; 5; 6; 7|]|]
# let increment_all arr =
     for y = 0 to Array.length arr - 1 do
        for x = 0 to Array.length arr.(y) - 1 do
           arr.(y).(x) <- arr.(y).(x) + 1
        done
     done;;
val increment_all : int array array -> unit = <fun>
# increment_all foo;;
- : unit = ()
# foo;;
- : int array array = [|[|2; 3; 4|]; [|5; 6; 7; 8|]|]

Author:  Tubs [ Thu Nov 17, 2005 1:44 am ]
Post subject: 

*backs away slowly towards the door*

*runs*

Author:  wtd [ Thu Nov 17, 2005 2:08 am ]
Post subject: 

Here's just the function:

code:
let increment_all arr =
   for y = 0 to Array.length arr - 1 do
      for x = 0 to Array.length arr.(y) - 1 do
         arr.(y).(x) <- arr.(y).(x) + 1
      done
   done


That isn't so bad, is it? Smile

Author:  Tubs [ Thu Nov 17, 2005 12:31 pm ]
Post subject: 

Not trying to be a nuisance and post my 100 line program and ask why its not working, but I really don't know how to solve this problem. Since this program uses reading / writing from .txt files it crashes inside my IDE, but says that there are no errors. However, when i try to run the .exe that has a windows error as well so I am left with absolutely no idea on what is failing (I suspect it has something to do with the borders of the array). The .txt file is a 25x25 square of X's, with -'s along the border.

dev c++ Mad

code:

#include <stdio.h>
#define ROWS 25
#define COLS 25

void generate(char (*grid)[25], int y_dim);

int main(int argc, char *argv[])
{


int x, y, k, j, rep;
char cells[ROWS][COLS], i;

FILE *in;         //Pointers to open and close the file

in = fopen( "data.txt", "r" );    // open a file for reading

for(y = 0; y < 25; ++y)

{
    for(x = 0; x < 25; ++x)

        {
        fscanf(in, "%c", &cells[x][y] );
        }
}

fclose (in);

for (k = 0; k < COLS; ++k)
      {
      printf ("%c", cells[j][k]);
      }

printf ("Enter 1 to generate again> ");
scanf ("%d", &rep);

if (rep == 1)
{

rep = 0;

do
{

  generate(cells, COLS - 1);

  for (j = 0; j < ROWS; ++j)

    {

    for (k = 0; k < COLS; ++k)
      {
      printf ("%c", cells[j][k]);
      }

  printf ("\n");

     }

printf ("Enter 1 to generate again> ");
scanf ("%d", &rep);

} while (rep = 1);
}

system ("pause");

  return 0;
}


void generate(char *grid[25], int y_dim)
{
   int x_i, y_i, friends = 0;

   for (y_i = 1; y_i < y_dim; y_i++)

   {
      for (x_i = 1; x_i < 24; x_i++)

      {

        if (grid[y_i - 1][x_i - 1] == 'O')
          friends++;

        if (grid[y_i - 1][x_i] == 'O')
          friends++;

        if (grid[y_i - 1][x_i + 1] == 'O')
          friends++;

        if (grid[y_i][x_i - 1] == 'O')
          friends++;

        if (grid[y_i][x_i + 1] == 'O')
          friends++;

        if (grid[y_i + 1][x_i - 1] == 'O')
          friends++;

        if (grid[y_i + 1][x_i] == 'O')
          friends++;

        if (grid[y_i + 1][x_i + 1] == 'O')
          friends++;

       /// Conditions

        if (grid[y_i][x_i] == 'O')

          // no survival code due to no changes

          if (friends >= 4 || friends < 2)  // death
             grid[y_i][x_i] = 'X';


        if (grid[y_i][x_i] == 'X')

          if (friends = 3)   // birth
            grid[y_i][x_i] == 'O';


      }

   }

}

Author:  Tubs [ Thu Nov 17, 2005 12:32 pm ]
Post subject: 

OH ya this is the game of life. If that helps.

Author:  wtd [ Thu Nov 17, 2005 12:57 pm ]
Post subject: 

Amazingly enough, well-formatted code is easier to work with.

Author:  Tubs [ Thu Nov 17, 2005 12:59 pm ]
Post subject: 

Whats wrong with that?

Author:  wtd [ Thu Nov 17, 2005 1:02 pm ]
Post subject: 

c:
#include <stdio.h>
#define ROWS 25
#define COLS 25

void generate(char (*grid)[25], int y_dim);

int main(int argc, char *argv[])
{
   int x, y, k, j, rep;
   char cells[ROWS][COLS], i;

   FILE *in;         //Pointers to open and close the file

   in = fopen("data.txt", "r");    // open a file for reading

   for (y = 0; y < 25; ++y)
   {
      for (x = 0; x < 25; ++x)
      {
         fscanf(in, "%c", &cells[x][y]);
      }
   }

   fclose (in);

   for (k = 0; k < COLS; ++k)
   {
      printf("%c", cells[j][k]);
   }

   printf("Enter 1 to generate again> ");
   scanf("%d", &rep);

   if (rep == 1)
   {
      rep = 0;

      do
      {
         generate(cells, COLS - 1);

         for (j = 0; j < ROWS; ++j)
         {
            for (k = 0; k < COLS; ++k)
            {
               printf("%c", cells[j][k]);
            }

            printf("\n");
         }

         printf("Enter 1 to generate again> ");
         scanf("%d", &rep);
      } while (rep = 1);
   }

   system ("pause");

   return 0;
}


void generate(char *grid[25], int y_dim)
{
   int x_i, y_i, friends = 0;

   for (y_i = 1; y_i < y_dim; y_i++)
   {
      for (x_i = 1; x_i < 24; x_i++)
      {
        if (grid[y_i - 1][x_i - 1] == 'O')
          friends++;

        if (grid[y_i - 1][x_i] == 'O')
          friends++;

        if (grid[y_i - 1][x_i + 1] == 'O')
          friends++;

        if (grid[y_i][x_i - 1] == 'O')
          friends++;

        if (grid[y_i][x_i + 1] == 'O')
          friends++;

        if (grid[y_i + 1][x_i - 1] == 'O')
          friends++;

        if (grid[y_i + 1][x_i] == 'O')
          friends++;

        if (grid[y_i + 1][x_i + 1] == 'O')
          friends++;

       /// Conditions

        if (grid[y_i][x_i] == 'O')

          // no survival code due to no changes

        if (friends >= 4 || friends < 2)  // death
           grid[y_i][x_i] = 'X';


        if (grid[y_i][x_i] == 'X')
           if (friends = 3)   // birth
              grid[y_i][x_i] == 'O';


      }
   }
}

Author:  Tubs [ Thu Nov 17, 2005 1:03 pm ]
Post subject: 

I dont know how to do super cool stuff like that Sad

Author:  wtd [ Thu Nov 17, 2005 1:07 pm ]
Post subject: 

Now, we try to compile this, and what happens?

code:
$ gcc life.c
life.c:64: error: conflicting types for 'generate'
life.c:5: error: previous declaration of 'generate' was here
life.c:64: error: conflicting types for 'generate'
life.c:5: error: previous declaration of 'generate' was here


Ok, what do we have on line 64?

Well, around line 64 we have...

c:
void generate(char *grid[25], int y_dim)


And we have an error about conflicting types. The next error is related to that.

What's on line 5?

c:
void generate(char (*grid)[25], int y_dim);


Oh hey look... they're not the same. Let's make them the same.

c:
#include <stdio.h>
#define ROWS 25
#define COLS 25

void generate(char (*grid)[25], int y_dim);

int main(int argc, char *argv[])
{
   int x, y, k, j, rep;
   char cells[ROWS][COLS], i;

   FILE *in;         //Pointers to open and close the file

   in = fopen("data.txt", "r");    // open a file for reading

   for (y = 0; y < 25; ++y)
   {
      for (x = 0; x < 25; ++x)
      {
         fscanf(in, "%c", &cells[x][y]);
      }
   }

   fclose (in);

   for (k = 0; k < COLS; ++k)
   {
      printf("%c", cells[j][k]);
   }

   printf("Enter 1 to generate again> ");
   scanf("%d", &rep);

   if (rep == 1)
   {
      rep = 0;

      do
      {
         generate(cells, COLS - 1);

         for (j = 0; j < ROWS; ++j)
         {
            for (k = 0; k < COLS; ++k)
            {
               printf("%c", cells[j][k]);
            }

            printf("\n");
         }

         printf("Enter 1 to generate again> ");
         scanf("%d", &rep);
      } while (rep = 1);
   }

   system ("pause");

   return 0;
}


void generate(char (*grid)[25], int y_dim)
{
   int x_i, y_i, friends = 0;

   for (y_i = 1; y_i < y_dim; y_i++)
   {
      for (x_i = 1; x_i < 24; x_i++)
      {
        if (grid[y_i - 1][x_i - 1] == 'O')
          friends++;

        if (grid[y_i - 1][x_i] == 'O')
          friends++;

        if (grid[y_i - 1][x_i + 1] == 'O')
          friends++;

        if (grid[y_i][x_i - 1] == 'O')
          friends++;

        if (grid[y_i][x_i + 1] == 'O')
          friends++;

        if (grid[y_i + 1][x_i - 1] == 'O')
          friends++;

        if (grid[y_i + 1][x_i] == 'O')
          friends++;

        if (grid[y_i + 1][x_i + 1] == 'O')
          friends++;

       /// Conditions

        if (grid[y_i][x_i] == 'O')

          // no survival code due to no changes

        if (friends >= 4 || friends < 2)  // death
           grid[y_i][x_i] = 'X';


        if (grid[y_i][x_i] == 'X')
           if (friends = 3)   // birth
              grid[y_i][x_i] == 'O';


      }
   }
}


Now let's compile again!

Oh look... it compiled fine.

Author:  wtd [ Thu Nov 17, 2005 1:09 pm ]
Post subject: 

Tubs wrote:
I dont know how to do super cool stuff like that Sad


You don't know how to use the space key to indent your code?

As for the rest...

code:
[syntax="c"]...[/syntax]

Author:  Tubs [ Thu Nov 17, 2005 1:22 pm ]
Post subject: 

My IDE said it compiled correctly... what a POS.

Author:  wtd [ Thu Nov 17, 2005 1:31 pm ]
Post subject: 

Hmmmm.... maybe there's a reason wtd advises against newbies using IDEs...

Nawww.... couldn't be.

Author:  Tubs [ Thu Nov 17, 2005 1:32 pm ]
Post subject: 

Even with those changes it has a windows error Confused

Author:  wtd [ Thu Nov 17, 2005 3:54 pm ]
Post subject: 

That would be a logic error, that's much more difficult to identify.

See, with C, any such error tends to make the program either stop dead in its tracks, or produce faulty output... and often both.

Author:  Tubs [ Thu Nov 17, 2005 4:23 pm ]
Post subject: 

Catching errors in your own code is hard, kind of like trying to fix grammatical mistakes in an essay you wrote. Of the three programs I have to write, not one work yet Embarassed

Author:  Tubs [ Thu Nov 17, 2005 4:48 pm ]
Post subject: 

ok. This code runs correctly up to the point where the letter being guessed is inputted, at which point it goes all to hell (compile it and see Shocked ). I have been looking at this all afternoon and I can't figure out what the heck is going wrong, so I guess it might be one of C's funny little quirks.

code:

#include <stdio.h>

int guessing (char target[5], char prev[25], char *cg);
void display (char guessed[25], char solved[5]);

int main(int argc, char *argv[])
{

int guesses, status, i, j;
char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
char current_guess;

printf ("HANGMAN:\n");

for (i = 0; i < 26; ++i)

    {
    guessed[i]= '*';
    }

for (i = 0; i < 6; ++i)

    {
    solved[i] = '-';
    }

printf ("How many guesses would you like to have> ");
scanf ("%d", &guesses);
printf ("\n");

for (i = 0; i <= guesses; ++i)
    {

   display(guessed, solved);
   status = guessing(word, guessed, &current_guess);

    for (j = 0; j < 6; j++)
      {
      if (status == i)
         {
         printf ("You got the letter %c!\n", word[i]);
         solved[i] = word[i];

         }
      }

    if (status == 6)
         {
         printf ("That letter is incorrect, try again!\n");
         }

     else if (status == 7)
         {
         printf ("That letter has already been guessed, try again!\n");
         }
    }

printf ("\n");

printf ("");

system ("pause");

  return 0;
}

int guessing (char target[5], char prev[25], char *cg)

{

char letter;
int j, i, char_code;

printf ("Guess a letter:> ");
scanf ("% c", letter);

char_code = (int)letter;

for (i = 0; i < 26; i++)
  {
  if (char_code == prev[i])
    return 7;
  }

if (letter == 'd')

  {
  return 0;
  }

else if (letter == 'o')

  {
  return 1;
  }

else if (letter == 'n')

  {
  return 2;
  }

else if (letter == 'k')

  {
  return 3;
  }

else if (letter = 'e')

  {
  return 4;
  }

else if (letter == 'y')

  {
  return 5;
  }

else
return 6;
}




Sorry for the hundred line program thing again, I would be more specific if I knew what I was looking for Confused

Author:  wtd [ Thu Nov 17, 2005 5:06 pm ]
Post subject: 

I appreciate that you're frustrated, but please clean up your code with proper indentation. I'm getting tired of doing it myself.

Author:  Tubs [ Thu Nov 17, 2005 7:09 pm ]
Post subject: 

What would you call proper? I was never told TO indent let alone how to do it.

Author:  wtd [ Thu Nov 17, 2005 7:16 pm ]
Post subject: 

Take a loot at the code I've posted.

Author:  Tubs [ Thu Nov 17, 2005 7:28 pm ]
Post subject: 

Hows this?

c:


#include <stdio.h>

int guessing (char target[5], char prev[25], char *cg);
void display (char guessed[25], char solved[5]);

int main(int argc, char *argv[])
{

int guesses, status, i, j;
char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
char current_guess;

printf ("HANGMAN:\n");

for (i = 0; i < 26; ++i)
{
   guessed[i]= '*';
}

for (i = 0; i < 6; ++i)
{
   solved[i] = '-';
}

printf ("How many guesses would you like to have> ");
scanf ("%d", &guesses);
printf ("\n");

for (i = 0; i <= guesses; ++i)
{
   display(guessed, solved);
   status = guessing(word, guessed, &current_guess);

   for (j = 0; j < 6; j++)
   {
      if (status == i)
      {
         printf ("You got the letter %c!\n", word[i]);
         solved[i] = word[i];
      }
   }

    if (status == 6)
    {
       printf ("That letter is incorrect, try again!\n");
    }

    else if (status == 7)
    {
       printf ("That letter has already been guessed, try again!\n");
    }
}

printf ("\n");

printf ("");

system ("pause");

  return 0;
}

int guessing (char target[5], char prev[25], char *cg)

{

char letter;
int j, i, char_code;

printf ("Guess a letter:> ");
scanf ("% c", letter);
char_code = (int)letter;

for (i = 0; i < 26; i++)
{
   if (char_code == prev[i])
      return 7;
}

if (letter == 'd')
{
   return 0;
}

else if (letter == 'o')
{
   return 1;
}

else if (letter == 'n')
{
   return 2;
}

else if (letter == 'k')
{
   return 3;
}

else if (letter = 'e')
{
   return 4;
}

else if (letter == 'y')
{
   return 5;
}

else
   return 6;

}

void display (char guessed[25], char solved[5])

{

int i;

printf ("You have used the letters: ");

for (i = 0; i <= 25; ++i)
{
   printf ("%c", guessed[i]);
}

printf ("\n");
printf ("The word so far is: ");

for (i = 0; i <= 5; ++i)
{
   printf ("%c", solved[5]);
}

printf ("\n");
}


Author:  wtd [ Thu Nov 17, 2005 7:35 pm ]
Post subject: 

Why don't you indent code in functions?

Author:  [Gandalf] [ Thu Nov 17, 2005 7:44 pm ]
Post subject: 

Get rid of all those unneccessary spaces between if statements. If anything, try to be consistent in how you intent throughout the program (not what you seem to be doing).

Author:  Tubs [ Thu Nov 17, 2005 7:55 pm ]
Post subject: 

wtd wrote:
Why don't you indent code in functions?


I had them as seperate units in the project and copied them seperately.

Ok, second try.

c:

#include <stdio.h>

int guessing (char target[5], char prev[25], char *cg);
void display (char guessed[25], char solved[5]);

int main(int argc, char *argv[])
{

int guesses, status, i, j;
char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
char current_guess;

printf ("HANGMAN:\n");

for (i = 0; i < 26; ++i)
{
   guessed[i]= '*';
}
for (i = 0; i < 6; ++i)
{
   solved[i] = '-';
}

printf ("How many guesses would you like to have> ");
scanf ("%d", &guesses);
printf ("\n");

for (i = 0; i <= guesses; ++i)
{
   display(guessed, solved);
   status = guessing(word, guessed, &current_guess);
   for (j = 0; j < 6; j++)
   {
      if (status == i)
      {
         printf ("You got the letter %c!\n", word[i]);
         solved[i] = word[i];
      }
   }

    if (status == 6)
    {
       printf ("That letter is incorrect, try again!\n");
    }
    else if (status == 7)
    {
       printf ("That letter has already been guessed, try again!\n");
    }
}

printf ("\n");

printf ("");

system ("pause");

  return 0;
}

int guessing (char target[5], char prev[25], char *cg)
{

  char letter;
  int j, i, char_code;

  printf ("Guess a letter:> ");
  scanf ("% c", letter);
  char_code = (int)letter;

  for (i = 0; i < 26; i++)
  {
     if (char_code == prev[i])
        return 7;
  }

  if (letter == 'd')
     return 0;
  else if (letter == 'o')
     return 1;
  else if (letter == 'n')
     return 2;
  else if (letter == 'k')
     return 3;
  else if (letter = 'e')
     return 4;
  else if (letter == 'y')
     return 5;
  else
     return 6;
}

void display (char guessed[25], char solved[5])

{

  int i;

  printf ("You have used the letters: ");

  for (i = 0; i <= 25; ++i)
  {
     printf ("%c", guessed[i]);
  }

  printf ("\n");
  printf ("The word so far is: ");

  for (i = 0; i <= 5; ++i)
  {
     printf ("%c", solved[5]);
  }

  printf ("\n");
}

Author:  wtd [ Thu Nov 17, 2005 7:58 pm ]
Post subject: 

And yet, still no indentation in the main function.

Also, when you use indentation, use it consistently. Don't indent with two spaces in some places and three in another.

Author:  Tubs [ Thu Nov 17, 2005 8:05 pm ]
Post subject: 

c:

#include <stdio.h>

int guessing (char target[5], char prev[25], char *cg);
void display (char guessed[25], char solved[5]);

int main(int argc, char *argv[])
{

  int guesses, status, i, j;
  char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
  char current_guess;

  printf ("HANGMAN:\n");

  for (i = 0; i < 26; ++i)
  {
     guessed[i]= '*';
  }
  for (i = 0; i < 6; ++i)
  {
     solved[i] = '-';
  }

  printf ("How many guesses would you like to have> ");
  scanf ("%d", &guesses);
  printf ("\n");

  for (i = 0; i <= guesses; ++i)
  {
     display(guessed, solved);
     status = guessing(word, guessed, &current_guess);
     for (j = 0; j < 6; j++)
     {
        if (status == i)
        {
           printf ("You got the letter %c!\n", word[i]);
           solved[i] = word[i];
        }
     }

      if (status == 6)
        printf ("That letter is incorrect, try again!\n");
      else if (status == 7)
        printf ("That letter has already been guessed, try again!\n");
  }

  printf ("\n");
  printf ("");
  system ("pause");

  return 0;
}

int guessing (char target[5], char prev[25], char *cg)
{

  char letter;
  int j, i, char_code;

  printf ("Guess a letter:> ");
  scanf ("% c", letter);
  char_code = (int)letter;

  for (i = 0; i < 26; i++)
  {
     if (char_code == prev[i])
        return 7;
  }

  if (letter == 'd')
     return 0;
  else if (letter == 'o')
     return 1;
  else if (letter == 'n')
     return 2;
  else if (letter == 'k')
     return 3;
  else if (letter = 'e')
     return 4;
  else if (letter == 'y')
     return 5;
  else
     return 6;
}

void display (char guessed[25], char solved[5])

{

  int i;

  printf ("You have used the letters: ");

  for (i = 0; i <= 25; ++i)
  {
     printf ("%c", guessed[i]);
  }

  printf ("\n");
  printf ("The word so far is: ");

  for (i = 0; i <= 5; ++i)
  {
     printf ("%c", solved[5]);
  }

  printf ("\n");
}


I didn't see any places where I incremented incorrectly Confused

Author:  wtd [ Thu Nov 17, 2005 8:18 pm ]
Post subject: 

c:
int main(int argc, char *argv[])
{

  int guesses, status, i, j;
  char guessed[26], word[6] = {'d', 'o', 'n', 'k', 'e', 'y'} , solved[6];
  char current_guess;

  printf ("HANGMAN:\n");

  for (i = 0; i < 26; ++i)
  {
     guesse


Notice how when you indent the contents of the function, you use two spaces? You do that consistently, which is good, but...

When you get to something like the for loop, you indent 3 spaces. Smile

Author:  Tubs [ Thu Nov 17, 2005 8:21 pm ]
Post subject: 

Ah ok. So now that the indenting issue is out of the way, any ideas on where the logic error(s) is?

Author:  wtd [ Thu Nov 17, 2005 8:31 pm ]
Post subject: 

Well, one error at a time.

Line 61:

c:
scanf ("% c", letter);


The space between "%" and "c" will cause a problem, as will the fact that you are using "letter", which passes the value of the variable, rather than "&letter", which passes a pointer to that variable.

Author:  Tubs [ Thu Nov 17, 2005 8:35 pm ]
Post subject: 

I was told to do that to bypass some logic error that occurs when the return key is hit before the scanf, and the value for return is used in place of the letter.

Author:  Tubs [ Thu Nov 17, 2005 8:41 pm ]
Post subject: 

In fact, it happens right here. After you enter the amount of guesses you want, it records the return as the letter you want to guess.

Author:  Tubs [ Thu Nov 17, 2005 8:43 pm ]
Post subject: 

I put the space in the wrong spot. Rolling Eyes

Author:  Tubs [ Thu Nov 17, 2005 9:51 pm ]
Post subject: 

Ok, I think I caught all of them. I will post the program once its done Smile

Author:  Tubs [ Thu Nov 17, 2005 10:06 pm ]
Post subject: 

Ok, here is #1 done. Game of life next ... Confused Thank you so much for your help wtd Very Happy

Author:  [Gandalf] [ Thu Nov 17, 2005 10:08 pm ]
Post subject: 

It would help if you didn't make 5 consecutive posts Evil or Very Mad. You should know well enough there is an edit button, and that posts like "I will post the program once its done" are not neccessary.

Author:  [Gandalf] [ Thu Nov 17, 2005 10:10 pm ]
Post subject: 

Well, silly me, there is no edit button! Still, limit your posts to important things.

I don't like this idea of no 'edit' button in help forums, it really causes more trouble than it solves (afaik).

Author:  md [ Thu Nov 17, 2005 10:18 pm ]
Post subject: 

Why is there no edit button?! Tony... I blame tony...

Author:  wtd [ Thu Nov 17, 2005 10:37 pm ]
Post subject: 

Hopefully you realize that an executable tells me precisely squat. Smile

Author:  Tubs [ Thu Nov 17, 2005 10:39 pm ]
Post subject: 

wtd wrote:
Hopefully you realize that an executable tells me precisely squat. Smile


Yes I do Smile It was just to show off.


: