Good day everyone!

I would like to ask some problem about the program I am currently working (hangman to be specific). Since I am just a beginner, there are many things I would like to clarify. I would like to ask your help so that I can enable more to see what are my errors in my code. It is too many to ask. Please bear with me and sorry for the inconvenience.

1. I do have 4 categories (three rounds). The user will choose a category. For every round, a different category. You cannot choose the same category in different rounds. After choosing a category, the game will provide a random word. At this moment, i have done only the random part (and it might some errors too.)

2. I am also having difficulty in underscores and spaces. You see, I only guessed that part. I do not know if that will work (or maybe it will destroy my whole program.)

3. Will you give me some advices on how to check inputs and how to display the letters which are used already for a specific round? I am not merely asking for code (though it will be gladly accepted it) but some detailed explanations.

You see, my program is not yet finished. Sorry if you are kind of frustrated to see such kind of code. I have spent a week just for that long code and my head is spinning already. But then, I really want to understand this language. I just need some guidance from the experts and experienced people out there.

I have attached my code (for the hangman program). Please check it.

Thank you in advance. Hope that you can help me with this as soon as you can.

Attachments
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

//structure
struct GuessWord
{
    char Category[50];//name of the category
    char Word[100];//word to be guessed
    char Guessletter;//letter used for guessing
};
typedef struct GuessWord GuessWord;

//functions
int Category (int categoryno);
int Round1(int w);//first round
int Round2(int x);//second round
int Round3(int y);//third round
int inputerror(char b);//checking if the input is a letter or !
int checkinput(char c);//checking for input
int searchinput (char d);//checking the input in the word
int result (char e);//showing if the input is present of not


//global variables
char name[20];
GuessWord Salita[100];
GuessWord Letter;
int categoryno;

int main (void)
{
    int i, a, z=3, flag=0, n;
    int countmain=0;//counter for main menu
    char choice[26];
    char test[100];

    printf("Enter your name:");//inputs the name of the user
    gets(name);//name. May receive special characters
    printf("\nHello %s!, Welcome to C-Hangaroo!\n", name);//welcomes the user. :D
    printf("To play, choose a category and guess the word under that category.\n");//intsructions
    printf("Enter an alphabet and press enter.\n");
    printf("To guess the whole phrase, enter '!'\n");
    printf("There will be three rounds in this game.\n");
    printf("Hope you enjoy this!\n");

    printf("\t\t============================================\n");//creative purposes only

    printf("Please choose a category. Press:\n");//categories to be choose from
    printf("1 --> Academic Buildings.\n");
    printf("2 --> Food Trip!\n");
    printf("3 --> Phrase/Quotes anyone?\n");
    printf("4 --> Himitsu! Karu-chan's Category./n");
    scanf("%d", &categoryno);

    while(countmain!=3)//since there will be three rounds
    {
        Category(categoryno);
        if(countmain==0)
        {
            Round1(categoryno);
        }else if(countmain==1)
        {
            Round2(categoryno);
        }else if(countmain==2)
        {
            Round3(categoryno);
        }

        countmain++;
    }

return 0;
}


int Category (int categoryno)
{
    int n, z=3;
    if (categoryno == 1)
        {
            n=rand()%z;//randoms the Salita[n].Word
            strcpy(Salita[0].Category, "Academic Building\0");
            strcpy(Salita[0].Word, "College of Arts and Letters\0");
            strcpy(Salita[1].Word, "The UP Alumni Engineer's Centennial Hall  Department of Computer Science and Engineering Library II\0");
            strcpy(Salita[2].Word, "National Institute of Geological Science\0");

            Salita[n].Word;
        }
        else if (categoryno == 2)
        {
            n=rand()%z;
            strcpy(Salita[1].Category, "Food Trip!\0");
            strcpy(Salita[0].Word, "Mcdonald's\0");
            strcpy(Salita[1].Word, "Lutong Bahay ( since 1977 )\0");
            strcpy(Salita[2].Word, "Food Stalls\0");

            Salita[n].Word;
        }
        else if (categoryno == 3)
        {
            n=rand()%z;
            strcpy(Salita[2].Category, "Phrases/Quotes anyone?\0");
            strcpy(Salita[0].Word, "You never know what you have till you lose it. You never get it back./n -snatcher/0");
            strcpy(Salita[1].Word, "Beware, so long as you live, of judging men by their outward appearance.\n -Jean de La Fontaine\0");
            strcpy(Salita[2].Word, "Curiosity. The reason why most of us haven't commited suiucide long ago.\n -Anonymous\0");

            Salita[n].Word;
        }
        else if (categoryno == 4)
        {
            n=rand()%z;
            strcpy(Salita[3].Category, "Himitsu! Karu-chan's Category\0");
            strcpy(Salita[0].Word, "Only the ring finger knows - the ring will confess his love\0");
            strcpy(Salita[1].Category, "Lelouch Vi Britannia --) Lelouch Lamperouge\0");
            strcpy(Salita[2].Word, "Uragiri wa boku no namae wo shitteiru\0");

            Salita[n].Word;
        }
    return n;//returns the n bases on the random done
}

int Round1(int w)
{
    int f, g=0, count1=0;
    char test1[100];
    char test2[100];
    printf("\t\t\t\tThis is Round 1.\n");
    printf("\t\t\tYou have choose the category %s", categoryno);
    printf("For this round, you have only 5 lives or else, game over!\n");
    printf("Now let's play round 1\n");

    printf("%s", categoryno);

    for(f=0;f<strlen(Salita[w].Word);f++)
    {
        test1[f]='_';
    }

    for(f=0;f<(strlen(Salita[w].Word)+1);f++)
    {
        test2[f]=' ';
    }

    printf("%s", name);

    while(count1!=5 && g<strlen(Salita[w].Word))
    {
        printf("\n");
        printf("Mistakes:%d", count1++);

        printf("Enter guess:");
        scanf("%s", &Letter.Guessletter);
        tolower(Letter.Guessletter);

        checkinput(Letter.Guessletter);
        searchinput(Letter.Guessletter);
        result(Letter.Guessletter);

        if(result!=0)
        {
            count1++;
        }
    }

    if(count1==5)
    {
        printf("Game over! Man, that's too bad! Try to guess harder! See you next time!/n");
        return 1;
    }else
    {
        return 0;
    }

}

int Round2(int x)
{
    int f, g=0, count2=0;
    char test1[100];
    char test2[100];
    printf("\t\t\t\tThis is Round 2.\n");
    printf("\t\t\tYou have choose the category %s", categoryno);
    printf("For this round, you have only 4 lives or else, game over!\n");
    printf("Now let's play round 2\n");

    printf("%s", categoryno);

    for(f=0;f<strlen(Salita[x].Word);f++)
    {
        test1[f]='_';
    }

    for(f=0;f<(strlen(Salita[x].Word)+1);f++)
    {
        test2[f]=' ';
    }

    printf("%s", name);

    while(count2!=4 && g<strlen(Salita[x].Word))
    {
        printf("\n");
        printf("Mistakes:%d", count2++);

        printf("Enter guess:");
        scanf("%s", &Letter.Guessletter);
        tolower(Letter.Guessletter);

        checkinput(Letter.Guessletter);
        searchinput(Letter.Guessletter);
        result(Letter.Guessletter);

        if(result!=0)
        {
            count2++;
        }
    }
    if(count2==4)
    {
        printf("Whew. Too bad. You did not make it to the last round. At least you've tried.\n");
        return 1;
    }else
    {
        return 0;
    }
}

int Round3(int y)
{
    int f, g=0, count3;
    char test1[100];
    char test2[100];
    printf("\t\t\t\tThis is Round 3.\n");
    printf("\t\t\tYou have choose the category %s", categoryno);
    printf("For this round, you have only 3 lives or else, game over!\n");
    printf("Now let's play round 3\n");

    printf("%s", categoryno);

    for(f=0;f<strlen(Salita[y].Word);f++)
    {
        test1[f]='_';
    }

    for(f=0;f<(strlen(Salita[y].Word)+1);f++)
    {
        test2[f]=' ';
    }

    printf("%s", name);

    while(count3!=3 && g<strlen(Salita[y].Word))
    {
        printf("\n");
        printf("Mistakes:%d", count3++);

        printf("Enter guess:");
        scanf("%s", &Letter.Guessletter);
        tolower(Letter.Guessletter);

        checkinput(Letter.Guessletter);
        searchinput(Letter.Guessletter);
        result(Letter.Guessletter);

        if(result!=0)
        {
            count3++;
        }
    }
    if(count3==3)
    {
        printf("What! That was too close. Tsk tsk. Sorry.\n");
        return 1;
    }else
    {
        printf("Wow! You are good! Congratulations!\n");
        return 0;
    }
}

int inputerror(char b)
{



}

int checkinput(char c)
{

}

int searchinput (char d)
{


}

int result (char e)
{


}

maybe this will be of some use. Its C++ version of hangman.
Its from C++ Primer Plus 5th edition. I copied and pasted for you.

// hangman.cpp -- some string methods
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cctype>

using std::string;

const int NUM = 26;

const string wordlist[NUM] = {"apiary", "beetle", "cereal",
"danger", "ensign", "florid", "garage", "health", "insult",
"jackal", "keeper", "loaner", "manage", "nonce", "onset",
"plaid", "quilt", "remote", "stolid", "train", "useful",
"valid", "whence", "xenon", "yearn", "zippy"};
int main()
{
	using std::cout;
	using std::cin;
	using std::tolower;
	using std::endl;

	std::srand(unsigned(std::time(0)));

	char play;

	cout << "Will you play a word game? <y/n> ";
	cin >> play;
	
	play = tolower(play);

	while (play == 'y')
	{
		string target = wordlist[std::rand() % NUM];
		int length = target.length();
		string attempt(length, '-');
		string badchars;
		int guesses = 6;
	cout << "Guess my secret word. It has " << length
	<< " letters, and you guess\n"
	<< "one letter at a time. You get " << guesses
	<< " wrong guesses.\n";
	cout << "Your word: " << attempt << endl;
	
	while (guesses > 0 && attempt != target)
	{
			char letter;
			cout << "Guess a letter: ";
			cin >> letter;
		if (badchars.find(letter) != string::npos
			|| attempt.find(letter) != string::npos)
			{
				cout << "You already guessed that. Try again.\n";
				continue;
			}

		int loc = target.find(letter);
		if (loc == string::npos)
		{
			cout << "Oh, bad guess!\n";
			--guesses;
			badchars += letter; // add to string
		}
		else
		{
			cout << "Good guess!\n";
			attempt[loc]=letter;
			// check if letter appears again
			loc = target.find(letter, loc + 1);
			while (loc != string::npos)
			{
				attempt[loc]=letter;
				loc = target.find(letter, loc + 1);
			}
		}
		cout << "Your word: " << attempt << endl;
		if (attempt != target)
		{
			if (badchars.length() > 0)
			cout << "Bad choices: " << badchars << endl;
			cout << guesses << " bad guesses left\n";
		}
	}
	if (guesses > 0)
		cout << "That’s right!\n";
	else
		cout << "Sorry, the word is " << target << ".\n";
		cout << "Will you play another? <y/n> ";
		cin >> play;
		play = tolower(play);
	}
	cout << "Bye\n";

	return 0;

}

I have already finished my program. There are several errors (problems I am encountering) in it. Please help me with this.

1. If one category was chosen by the user, it must not been chosen again in the next round. How can I do such thing?

2.

int inputerror(char b, char* h)
{
    int i;
    char alpha[27];
    strcpy(alpha, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    // change letters used from the alphabet to '_'
    for (i = 0; alpha[i] != '\0'; i++)
    {
        if ((alpha[i]) == h)
        {
            alpha[i] = '_';
        }
    }

    // pad with spaces so it appears in the middle of the screen
    printf("              ");

    for (i = 0; alpha[i] != '\0'; i++)
        printf("%c ", alpha[i]);
    printf("\n\n");

}

I am having difficulty with this code.
a. under what library(i.e stdio, stdlib) is strlwr, tolower and _tolower? do you think it requires in my code?
b. Is this code ok?

3. And how to do the part when the user inputs a letter, the underscores will be replaced by letter in a correct order?

Here are just some of my questions. Please see the attached file below for the whole code. If you see other errors, please tell me. I really need your advices regarding with this case.

Thanks in advance!

Attachments
//Hangman Game
//version 1

//preprocessor prototypes
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

//structure declaration
struct GuessWord
{
    char Category[50];
    char Word[100];
    char Guessletter;
    char guessword[100];
};
typedef struct GuessWord GuessWord;

//function prototypes
int Category (int categoryno);//main menu
int Round1(int w);//1st round of the game
int Round2(int x);//2nd round of the game
int Round3(int y);//3rd round of the game
int inputerror(char b, char* h);//display the alphabet
int checkinput(char c, char* q);//checking if the input is an alphabet or '!'
int searchinput (char d, char* k, char* l);//checking if the input is in the puzzle
int result (char* m, char* p);//result of the game if '!' was inputed.


char name[20];//name of the user
GuessWord Salita[100];
GuessWord Letter;
int categoryno;

int main (void)
{
    int i, a, z=3, flag=0, n;
    int countmain=0;//counter of main menu
    char choice[26];
    char test[100];

    printf("Enter your name:");//inputs the name of the user
    gets(name);//name. May receive special characters
    printf("\nHello %s!, Welcome to C-Hangaroo!\n", name);//welcomes the user. :D
    //intructions
    printf("To play, choose a category and guess the word under that category.\n");
    printf("Enter an alphabet and press enter.\n");
    printf("To guess the whole phrase, enter '!'\n");
    printf("There will be three rounds in this game.\n");
    printf("Hope you enjoy this!\n");

    printf("\t\t============================================\n");

    printf("Please choose a category. Press:\n");
    printf("1 --> Academic Buildings.\n");
    printf("2 --> Food Trip!\n");
    printf("3 --> Phrase/Quotes anyone?\n");
    printf("4 --> Himitsu! Karu-chan's Category./n");
    scanf("%d", &categoryno);

    while(countmain!=2)
    {
        Category(categoryno);
        if(countmain==0)
        {
            Round1(categoryno);
        }else if(countmain==1)
        {
            Round2(categoryno);
        }else if(countmain==2)
        {
            Round3(categoryno);
        }

        countmain++;
    }

    printf("\t\t\t\tThank you for playing Hangaroo!\n");
    printf("\t\t\tversion 1\n");

return 0;
}

//functions

int Category (int categoryno)
{
    int n, z=3;
    if (categoryno == 1)
        {
            n=rand()%z;
            strcpy(Salita[0].Category, "Academic Building\0");
            strcpy(Salita[0].Word, "College of Arts and Letters\0");
            strcpy(Salita[1].Word, "The UP Alumni Engineer's Centennial Hall  Department of Computer Science and Engineering Library II\0");
            strcpy(Salita[2].Word, "National Institute of Geological Science\0");

            Salita[n].Word;
        }
        else if (categoryno == 2)
        {
            n=rand()%z;
            strcpy(Salita[1].Category, "Food Trip!\0");
            strcpy(Salita[0].Word, "Mcdonald's\0");
            strcpy(Salita[1].Word, "Lutong Bahay ( since 1977 )\0");
            strcpy(Salita[2].Word, "Food Stalls\0");

            Salita[n].Word;
        }
        else if (categoryno == 3)
        {
            n=rand()%z;
            strcpy(Salita[2].Category, "Phrases/Quotes anyone?\0");
            strcpy(Salita[0].Word, "You never know what you have till you lose it. You never get it back./n -snatcher/0");
            strcpy(Salita[1].Word, "Beware, so long as you live, of judging men by their outward appearance.\n -Jean de La Fontaine\0");
            strcpy(Salita[2].Word, "Curiosity. The reason why most of us haven't commited suiucide long ago.\n -Anonymous\0");

            Salita[n].Word;
        }
        else if (categoryno == 4)
        {
            n=rand()%z;
            strcpy(Salita[3].Category, "Himitsu! Karu-chan's Category\0");
            strcpy(Salita[0].Word, "Only the ring finger knows - the ring will confess his love\0");
            strcpy(Salita[1].Category, "Lelouch Vi Britannia --) Lelouch Lamperouge\0");
            strcpy(Salita[2].Word, "Uragiri wa boku no namae wo shitteiru\0");

            Salita[n].Word;
        }
    return n;
}

int Round1(int w)
{
    int f, g=0, count1=0, length;
    char test1[100];
    char test2[100];
    length=strlen(Salita[w].Word);

    printf("\t\t\t\tThis is Round 1.\n");
    printf("\t\t\tYou have choose the category %s", categoryno);
    printf("For this round, you have only 5 lives or else, game over!\n");
    printf("Now let's play round 1\n");

    printf("%s", categoryno);

    for(f=0;f<length;f++)
    {
        test1[f]='_';
    }

    for(f=0;f<length+1;f++)
    {
        test2[f]=' ';
    }

    printf("%s", name);

    while((count1!=5 && g<length))
    {
        printf("\n");
        printf("Mistakes:%d", count1++);

        printf("Enter guess:");
        scanf("%s", &Letter.Guessletter);
        if(Letter.Guessletter == '!')
        {
            printf("Guess the phrase NOW! If your guess is correct, you win. Else, you lose and your game is now over!\n");
            gets(Letter.guessword);
            result(Letter.guessword, Salita[w].Word);
        }

        inputerror(Letter.Guessletter, Salita[w].Word);
        checkinput(Letter.Guessletter, Salita[w].Word);
        searchinput(Letter.Guessletter, Salita[w].Word, test1);

        if(searchinput!=0)
        {
            count1++;
        }
    }

    if(count1==5)
    {
        printf("Game over! Man, that's too bad! Try to guess harder! See you next time!/n");
        return 1;
    }else
    {
        return 0;
    }

}

int Round2(int x)
{
    int f, g=0, count2=0, length;
    char test1[100];
    char test2[100];
    length=strlen(Salita[x].Word);

    printf("\t\t\t\tThis is Round 2.\n");
    printf("\t\t\tYou have choose the category %s", categoryno);
    printf("For this round, you have only 4 lives or else, game over!\n");
    printf("Now let's play round 2\n");

    printf("%s", categoryno);

    for(f=0;f<length;f++)
    {
        test1[f]='_';
    }

    for(f=0;f<length+1;f++)
    {
        test2[f]=' ';
    }

    printf("%s", name);

    while((count2!=4 && g<length))
    {
        printf("\n");
        printf("Mistakes:%d", count2++);

        printf("Enter guess:");
        scanf("%s", &Letter.Guessletter);
        if(Letter.Guessletter == '!')
        {
            printf("Guess the phrase NOW! If your guess is correct, you win. Else, you lose and your game is now over!\n");
            gets(Letter.guessword);
            result(Letter.guessword, Salita[x].Word);
        }

        inputerror(Letter.Guessletter, Salita[x].Word);
        checkinput(Letter.Guessletter, Salita[x].Word);
        searchinput(Letter.Guessletter, Salita[x].Word, test1);


        if(searchinput!=0)
        {
            count2++;
        }
    }
    if(count2==4)
    {
        printf("Whew. Too bad. You did not make it to the last round. At least you've tried.\n");
        return 1;
    }else
    {
        return 0;
    }
}

int Round3(int y)
{
    int f, g=0, count3, length;
    char test1[100];
    char test2[100];
    length=strlen(Salita[y].Word);

    printf("\t\t\t\tThis is Round 3.\n");
    printf("\t\t\tYou have choose the category %s", categoryno);
    printf("For this round, you have only 3 lives or else, game over!\n");
    printf("Now let's play round 3\n");

    printf("%s", categoryno);

    for(f=0;f<length;f++)
    {
        test1[f]='_';
    }

    for(f=0;f<length+1;f++)
    {
        test2[f]=' ';
    }

    printf("%s", name);

    while(count3!=3 && g<length)
    {
        printf("\n");
        printf("Mistakes:%d", count3++);

        printf("Enter guess:");
        scanf("%s", &Letter.Guessletter);
        if(Letter.Guessletter == '!')
        {
            printf("Guess the phrase NOW! If your guess is correct, you win. Else, you lose and your game is now over!\n");
            gets(Letter.guessword);
            result(Letter.guessword, Salita[y].Word);
        }

        inputerror(Letter.Guessletter, Salita[y].Word);
        checkinput(Letter.Guessletter, Salita[y].Word);
        searchinput(Letter.Guessletter, Salita[y].Word, test1);

        if(searchinput!=0)
        {
            count3++;
        }
    }
    if(count3==3)
    {
        printf("What! That was too close. Tsk tsk. Sorry.\n");
        return 1;
    }else
    {
        printf("Wow! You are good! Congratulations!\n");
        return 0;
    }
}
int inputerror(char b, char* h)
{
    int i;
    char alpha[27];
    strcpy(alpha, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    // change letters used from the alphabet to '_'
    for (i = 0; alpha[i] != '\0'; i++)
    {
        if ((alpha[i]) == h)
        {
            alpha[i] = '_';
        }
    }

    // pad with spaces so it appears in the middle of the screen
    printf("              ");

    for (i = 0; alpha[i] != '\0'; i++)
        printf("%c ", alpha[i]);
    printf("\n\n");

}

int checkinput(char c, char* q)//checks if the input is an alphabet or '!'. otherwise, it is an invalid input
{
    char alpha[27], i;
    strcpy(alpha, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    for (i = 0; alpha[i] != '\0'; i++)
    {
        if ( c == (alpha[i]))
        {
            return 0;
        }
    }
    if (c == '!')
    {
        return 0;
    }
    else
    {
        printf("This is an invalid input. Alphabets and '!' are only considered.\n");
        return 1;
    }

}

int searchinput (char d, char* k, char* l)
{
    int o, s=0, length;
    length=strlen(k);

    for(o=0;(o<length);o++)
    {
        if(k[o] == d)
        {
            printf("%s", l[o]);
        }else if(k[o] != d)
            s=1;
    }

}
int result (char* m, char* p)
{
    int t, u=0, length;
    length=strlen(p);

    for(t=0; (t<length); t++)
    {
        if(m[t] == p[t])
        {
            printf("You're right\n");
        }else
        {
            pr

If you look at the code I posted, you would see that
there is a badchar string, which hold all the guesses.
when the user enters a letter, it checks if he already guessed that
by checking if its in badchar.

You can do similar in c.

char badchar[256] = "";
int badCharIndx = 0;
//get user input
//check if user's input exist in badchar
//if not then add it into badchar
badchar[badCharIndx++] = user's input

It is quite a help though what i need is that when a letter was input (by the user), like in the hangman, all the letters used in the puzzle will be marked by a line or an asterisk. it does not really need to have the badchar though.

in you while loop display all letters(maybe on the right side of the screen).
And turn by turn, remove the letters that has been picked. So the user
can see which letters he could get to choose from.

Answers
1) take array of int catg[4] = {0, 0, 0, 0}
now once a category is chosen set that array index.
suppose catg 1 is chosen then catg[0] = 1;
insert code to test if catg is set, yes break

 if (categoryno == 1)

    {

        if( catg[0])
        {
           printf("choose other catg")
           return;
       }
        /*your code*/

    }

2) ctype.h

3) reprint at the same place. use printf("b") to do this.

 printf("forum");
 printf("bbbbbb");
 printf("hello");

Edited 3 Years Ago by mike_2000_17: Fixed formatting

>>codeguru_2009
please see this code:

int catg[4]={0,0,0,0};

printf("Please choose a category\n");
printf("1\n");
printf("2\n");
printf("3\n");
scanf("%d", categoryno);

if(categoryno==1)
{
   catg[0]=1;
   if( catg[0])
   {
          printf("choose other catg");
   }
     return;
}

if(categoryno==2)
{
   catg[1]=1;
   if( catg[0])
   {
          printf("choose other catg");
   }
     return;
}

"insert code to test if catg is set, yes break "

--) i do not get it. how is that?? :|

My answers were not complete. all was hint only.
It works like this

void Category (int categoryno)
{

    int n, z=3;
    if (categoryno == 1)
    {
            if(catg[0]) 
           {
               printf("category already chosen");
               return;
           }
            catg[0] = 1;
             n=rand()%z;//randoms the Salita[n].Word
            strcpy(Salita[0].Category, "Academic Building\0");
            strcpy(Salita[0].Word, "College of Arts and Letters\0");
            strcpy(Salita[1].Word, "The UP Alumni Engineer's Centennial Hall  Department of Computer Science and Engineering Library II\0");
            strcpy(Salita[2].Word, "National Institute of Geological Science\0");

           Salita[n].Word;

        }
        else if (categoryno == 2)
        {
                if(catg[1]) 
               {
                    printf("category already chosen");
                    return;
               }
               catg[1] = 1;
               n=rand()%z;
               strcpy(Salita[1].Category, "Food Trip!\0");
              strcpy(Salita[0].Word, "Mcdonald's\0");
              strcpy(Salita[1].Word, "Lutong Bahay ( since 1977 )\0");
              strcpy(Salita[2].Word, "Food Stalls\0");
             Salita[n].Word;
        }
        else if (categoryno == 3)
        {
             if (catg[2]) 
            {
                 printf("category already chosen");
                return;
           }
           catg[2] = 1;
            n=rand()%z;
            strcpy(Salita[2].Category, "Phrases/Quotes anyone?\0");
            strcpy(Salita[0].Word, "You never know what you have till you lose it. You never get it back./n -snatcher/0");
            strcpy(Salita[1].Word, "Beware, so long as you live, of judging men by their outward appearance.\n -Jean de La Fontaine\0");
            strcpy(Salita[2].Word, "Curiosity. The reason why most of us haven't commited suiucide long ago.\n -Anonymous\0");
            Salita[n].Word;
        }
        else if (categoryno == 4)
        {
               if(catg[3]) 
              {
                   printf("category already chosen");
                  return;
              }
              catg[3] = 1;
              n=rand()%z;
             strcpy(Salita[3].Category, "Himitsu! Karu-chan's Category\0");
             strcpy(Salita[0].Word, "Only the ring finger knows - the ring will confess his love\0");
             strcpy(Salita[1].Category, "Lelouch Vi Britannia --) Lelouch Lamperouge\0");
            strcpy(Salita[2].Word, "Uragiri wa boku no namae wo shitteiru\0");
            Salita[n].Word;
        }

    return ;// since u r making no use uf return value from category function make it as void.
}

hope this will help you

I got one idea though coz hang man doesnt require junk genrator names unless you do a real name genrator my idea is have the program read from you 3 names for the movies or any other names and it will choose randomly between the 3 or more if you want to then after ur done with them u can rewrite them or having program calloc for more if you need more than 3 names

I am having an error as I am editing my code

"warning: passing arg 1 of 'Round1' from the incompatible pointer type"

what does that mean? And how to solve such warning?

#include<stdio.h>

void Round1(char *Salita);

char Salita[3][100];

int main (void)
{
   //the user will ask the user the categories to be used for nth round
  //from the if statements, the code will produce Salita[n]
   //function call
   Round1(&Salita[n]; //is this correct? 
   ...
}

void Round1(char *Salita)
{
   ....
}

Function Round1() prototypes(line 3) says Its arguments should be a char pointer. so you can pass single dimension array as an argument when calling Round1.

calling function
{
  char *ptr;   // or char ptr[]
 Round1(ptr);  
}
Round1(char* pointer)  // or Round1(char pointer[])
{
//body
}
 // for double dimension array
 
calling function
{
  char **ptr;   // or char ptr[][x]x=positive integer
 Round1(ptr);  
}
Round1(char** pointer)  // or Round1(char pointer[][x]) 
//in case of 2D array you should always mention no. of columns.
{
//body
//use pointer as 2D
}

Yours way of calling function Round1 is correct.
But Round1 definition and prototype for arguments should contain 2D array declaration.
Round1(char salita[][100])
When you call like Round1(&salita[1]), then in salita in Round1 will have first index element as zeroth index element.

You are immediately adviced to read C book by Denis Ritchie.

Edited 7 Years Ago by codeguru_2009: c syntax highlighting

This article has been dead for over six months. Start a new discussion instead.