I need help writing an anagram that test 2 strings.

os: microsoft
compiler: visual studio

Here are some of the directions:

Read the first string, then write a loop that uses an array of 26 ints to count how many
times each letter has been seen.

Read the second string, this time decrement each letter’s count in the int array.
The strings are anagrams if every element in the int array is 0.

Ignore any characters that aren’t letters. Treat upper-case letters as the same as their
lower-case equivalent.

compiling errors:
warning C4013: 'initialize' undefined; assuming extern returning int
warning C4013: 'getString' undefined; assuming extern returning int
warning C4013: 'setLetters' undefined; assuming extern returning int
error C2371: 'initialize' : redefinition; different basic types
error C2371: 'getString' : redefinition; different basic types
error C2371: 'setLetters' : redefinition; different basic types
warning C4013: 'isalpha' undefined; assuming extern returning int
warning C4013: 'tolower' undefined; assuming extern returning int

What do these errors mean? basically i need help finishing my program.

this is what i have no far:

void checkLetters(int narray[], char carray[]);
int isZero(int narray[]);

void main(void)
{
    int charNums[LETTERS], i = 1;
    char word[MAX];

    do
    {
    initialize(charNums,word);
    printf("Enter your first statement: ");
    getString(word);
    setLetters(charNums, word);
    printf("Enter your second statement(""Quit"" to quit): ");
    getString(word);
    checkLetters(charNums, word);
    if(isZero(charNums))
        printf("Anagram\n");
    else
        printf("Not Anagram\n");
    if(!strcmp(word,"quit")||!strcmp(word, "Quit"))
        i = FALSE;
    }while(i);


}
void initialize(int narray[],char carray[])
{
    int i;
    for(i=0; i < LETTERS; ++i)
    {
        narray[i] = 0;
    }
    for(i=0; i<MAX; ++i)
    {
        carray[i] = '\0';
    }
}
void getString(char carray[])
{
    gets_s(carray, MAX - 1);
}
void setLetters(int narray[], char carray[])
{
    int i = 0;
    while(carray[i])
    {
        if(isalpha(carray[i]))
        {
            carray[i] = tolower(carray[i]);
            narray[(int) (carray[i] - 'a')] += 1;
        }
        i++;
    }
}
void checkLetters(int narray[], char carray[])
{
    int i = 0;
    while(carray[i])
    {
        if(isalpha(carray[i]))
        {
            carray[i] = tolower(carray[i]);
            narray[(int) (carray[i]-'a')] -= 1;
        }
        i++;
    }
}
int isZero(int narray[])
{
    int i;
    for(i=0; i < LETTERS; ++i)
    {
        if(narray[i] != 0)
        {
            return FALSE;
        }
    }
    return TRUE;
}

What are your include files for this program? You left them off.

What are your include files for this program? You left them off.

oh sorry. its just #include <stdio.h> and <string.h>

Hopefully this will make it easier to see where the compiling errors are

sry disregard the post above i meant to say <ctype.h> not <string.h>

#include <stdio.h>
#include <ctype.h>

void checkLetters(int narray[], char carray[]);
int isZero(int narray[]);

void main(void)
{
    int charNums[LETTERS], i = 1;
    char word[MAX];

    do
    {
    initialize(charNums,word); <---warning C4013: 'initialize' undefined; assuming extern returning int
    printf("Enter your first statement: ");
    getString(word); <---warning C4013: 'getString' undefined; assuming extern returning int
    setLetters(charNums, word);<---warning C4013: 'setLetters' undefined; assuming extern returning int
    printf("Enter your second statement(""Quit"" to quit): ");
    getString(word);
    checkLetters(charNums, word);
    if(isZero(charNums))
        printf("Anagram\n");
    else
        printf("Not Anagram\n");
    if(!strcmp(word,"quit")||!strcmp(word, "Quit")) <---'strcmp' undefined; assuming extern returning int
        i = FALSE;
    }while(i);


}
void initialize(int narray[],char carray[])
{ <---error C2371: 'initialize' : redefinition; different basic types
    int i;
    for(i=0; i < LETTERS; ++i)
    {
        narray[i] = 0;
    }
    for(i=0; i<MAX; ++i)
    {
        carray[i] = '\0';
    }
}
void getString(char carray[])
{ <---error C2371: 'getString' : redefinition; different basic types
    gets_s(carray, MAX - 1);
}
void setLetters(int narray[], char carray[])
{ <---error C2371: 'setLetters' : redefinition; different basic types
    int i = 0;
    while(carray[i])
    {
        if(isalpha(carray[i]))
        {
            carray[i] = tolower(carray[i]); 
            narray[(int) (carray[i] - 'a')] += 1;
        }
        i++;
    }
}
void checkLetters(int narray[], char carray[])
{
    int i = 0;
    while(carray[i])
    {
        if(isalpha(carray[i]))
        {
            carray[i] = tolower(carray[i]);
            narray[(int) (carray[i]-'a')] -= 1;
        }
        i++;
    }
}
int isZero(int narray[])
{
    int i;
    for(i=0; i < LETTERS; ++i)
    {
        if(narray[i] != 0)
        {
            return FALSE;
        }
    }
    return TRUE;
}

Add ctype.h for isalpha and tolower.

All your functions should have prototypes above main(). Preferably, right below the include files list and any defines you have.

That takes care of most of your errors. May raise some other errors, of course.

Make these changes, and re-compile and see what you have then. Also, repost your code so if we study it, we won't be looking at obsolete code.

It may not make a difference right now, to you, but most of us will receive a warning or an error for void main(void).

That is not standard C, and hasn't been standard C since J.C. was a Corporal. It's always int main(void), never void main(void). On the end of main, it's always return 0.

Yes, I know books leave it out, oftentimes - but that's wrong. It will cause some problems, down the line, and make warnings or errors, now.

lol I feel like an idiot. I must have not copied and pasted the top portion of it when I emailed it to myself from class. It works fine now. Thanks again Adak!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.