Thread: check for typing???

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    43

    Question check for typing???

    Hello, I started making this program where people would type there name in and it would put the meanning of there name on the screen. I ran in to a problem with comparing what they typed. Heres the code please tell me how I can make this work.

    Code:
    #include <stdio.h>
    #include <ctype.h>	//toupper function
    
    int main(void)
    {
    
    	int done;
    	char name, again;
    
    	done=0;
    	while(done)
    	{
    
    		printf("Enter your first name to get the meaning of it: ");
    		scanf("%s",&name);
    		name=toupper(name);
    
    	if(name=='KYLE')
            {
    	printf("\n\n\
    Kyle (m,f):  From a Scottish surname meaning \"narrow\"\n\
    or \"narrow channel\" (Gaelic).");
    	break;
    	}
    
    	else if(name=='ASHLEY')
    	printf("\n\n\
    ASHLEY (m,f):  From a surname which was originally derived from\n\
    a place name which meant \"ash tree clearing\" (Old English).");
    	break;
    	}
    
    	else if(name=='DEBORAH')
    	printf("\n\n\
    DEBORAH (f):  \"bee\" from the Hebrew name Devorah.\n\
    Deborah was the nurse of Rebecca in the Old Testament.\n\
    Also in the Old Testament, this was the name of a heroine\n\
    and prophetess who led the Israelites in defeating the Canaanites.");
    	break;
    	}
    
    	else if(name=='DANNY')
    	printf("\n\n\
    DANNY (m):  Pet form of DANIEL\n\
    DANIEL (m):  \"God is my judge\" from the Hebrew name Daniyel.\n\
    Daniel was a Hebrew prophet whose story is told in the Book of Daniel\n\
    in the Old Testament. He lived during the Jewish captivity in Babylon,\n\
    where he served in the court of the king, rising to prominence by\n\
    interpreting the king's dreams. The book also presents Daniel's four\n\
    visions of the end of the world. Famous bearers of this name include\n\
    English author Daniel Defoe, Swiss mathematician Daniel Bernoulli,\n\
    and American frontiersman Daniel Boone.");
    	break;
    	}
    
    	else if(name=='LAURIE')
    	printf("\n\n\
    LAURIE (f):  Pet form of LAURA\n\
    LAURA (f):  Feminine form of the Late Latin name Laurus,\n\
    which meant \"laurel\". In ancient Rome the leaves of laurel\n\
    trees were used to create victors' garlands. Saint Laura was\n\
    a 9th-century Spanish martyr, a nun who was thrown into a vat\n\
    of molten lead by the Moors. Another famous bearer was Laura Secord,\n\
    a Canadian heroine during the War of 1812.");
    	break;
    	}
    
    	else if(name=='STEPHEN')
            {
    	printf("\n\n\
    STEPHEN (m):  \"crown\" from Greek stephanos. Saint Stephen\n\
    was an early Christian martyr stoned to death as told in Acts\n\
    in the New Testament. Another Saint Stephen is the patron saint\n\
    of Hungary, was the first Christian king of that country (10th century).\n\
    As well, this was the name of kings of England, Serbia, and Poland\n\
    and ten popes. This name is also borne by physicist Stephen Hawking.");
    	break;
    	}
    
    	else if(name=='SARA')
            {
    	printf("\n\n\
    SARA (f):  Arabic, Greek, Spanish, Italian and Hungarian form of SARAH\n\
    SARAH (f):  \"lady\" or \"princess\" (Hebrew). This was the name of the\n\
    wife of Abraham in the Old Testament. She became the mother of Isaac\n\
    at the age of 90. Her name was originally Sarai, but God changed it\n\
    (see Genesis 17:15).");
    	break;
    	}
    
    
    	while(1)
    	{
    		printf("Want to see that again? Y/N: ");
    		again=toupper(getch());
    
    		if(again=='Y')
    			break;
    
    		else if(again=='N')
    		{
    			done=1;
    		}
    
    		else
    		{
    			printf("Hit [Y]es or [N]o");
    		}
    	}//end while(1)
    
    }//end while(done)
    
    return;
    }//end main(void)
    ()(ôô)()© MonKey ware
    Kyle J. R.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    your code
    Code:
    if(name=='KYLE')
    name is a string so your compiler should throw up warnings for comparisons like the one above.
    when comparing strings use...strcmp() in <string.h>
    and double quote your name.

    Code:
    if(!strcmp(name, "KYLE")
    go here for explanation of strcmp();

    http://www.cprogramming.com/fod/strcmp.html
    Last edited by bigtamscot; 03-03-2002 at 03:32 PM.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    43
    Ok I did the change, but it is still having problems, I eather get compilling errors (or if i edit it i dont get errors but the exe does nothing).

    Code:
    #include <stdio.h>	//Basic funtions
    #include <conio.h>	//getch function
    #include <ctype.h>	//toupper function
    #include <string.h>	//strcmp function
    
    int main(void)
    {
    
    	int done;
    	char name[20], again;
    
    	done=0;
    	while(done)
    	{
    
    		printf("Enter your first name to get the meaning of it: ");
    		scanf("%s",&name);
    		name=toupper(name);
    
    
    		if(!strcmp(name, "KYLE"))
    	                   {
    		printf("\n\n\
    Kyle (m,f):  From a Scottish surname meaning \"narrow\"\n\
    or \"narrow channel\" (Gaelic).");
    		break;
    		}
    
    		if(!strcmp(name, "ASHLEY"))
    		{
    		printf("\n\n\
    ASHLEY (m,f):  From a surname which was originally derived from\n\
    a place name which meant \"ash tree clearing\" (Old English).");
    		break;
    		}
    
    		if(!strcmp(name, "DEBORAH"))
    		{
    		printf("\n\n\
    DEBORAH (f):  \"bee\" from the Hebrew name Devorah.\n\
    Deborah was the nurse of Rebecca in the Old Testament.\n\
    Also in the Old Testament, this was the name of a heroine\n\
    and prophetess who led the Israelites in defeating the Canaanites.");
    		break;
    		}
    
    		if(!strcmp(name, "DANNY"))
    		{
    		printf("\n\n\
    DANNY (m):  Pet form of DANIEL\n\
    DANIEL (m):  \"God is my judge\" from the Hebrew name Daniyel.\n\
    Daniel was a Hebrew prophet whose story is told in the Book of Daniel\n\
    in the Old Testament. He lived during the Jewish captivity in Babylon,\n\
    where he served in the court of the king, rising to prominence by\n\
    interpreting the king's dreams. The book also presents Daniel's four\n\
    visions of the end of the world. Famous bearers of this name include\n\
    English author Daniel Defoe, Swiss mathematician Daniel Bernoulli,\n\
    and American frontiersman Daniel Boone.");
    		break;
    		}
    
    		if(!strcmp(name, "LAURIE"))
    		{
    		printf("\n\n\
    LAURIE (f):  Pet form of LAURA\n\
    LAURA (f):  Feminine form of the Late Latin name Laurus,\n\
    which meant \"laurel\". In ancient Rome the leaves of laurel\n\
    trees were used to create victors' garlands. Saint Laura was\n\
    a 9th-century Spanish martyr, a nun who was thrown into a vat\n\
    of molten lead by the Moors. Another famous bearer was Laura Secord,\n\
    a Canadian heroine during the War of 1812.");
    		break;
    		}
    
    		if(!strcmp(name, "STEPHEN"))
                          	{
    		printf("\n\n\
    STEPHEN (m):  \"crown\" from Greek stephanos. Saint Stephen\n\
    was an early Christian martyr stoned to death as told in Acts\n\
    in the New Testament. Another Saint Stephen is the patron saint\n\
    of Hungary, was the first Christian king of that country (10th century).\n\
    As well, this was the name of kings of England, Serbia, and Poland\n\
    and ten popes. This name is also borne by physicist Stephen Hawking.");
    		break;
    		}
    
    		if(!strcmp(name, "SARAH"))
                                           {
    		printf("\n\n\
    SARA (f):  Arabic, Greek, Spanish, Italian and Hungarian form of SARAH\n\
    SARAH (f):  \"lady\" or \"princess\" (Hebrew). This was the name of the\n\
    wife of Abraham in the Old Testament. She became the mother of Isaac\n\
    at the age of 90. Her name was originally Sarai, but God changed it\n\
    (see Genesis 17:15).");
    		break;
    		}
    
    
    		while(1)
    		{
    			printf("Want to see that again? Y/N: ");
    			again=toupper(getch());
    
    			if(again=='Y')
    				break;
    
    			else if(again=='N')
    			{
    				done=1;
    				break;
    			}
    
    			else
    			{
    				printf("Hit [Y]es or [N]o");
    			}
    		}//end while(1)
    
    	}//end while(done)
    
    return 0;
    }//end main(void)
    ()(ôô)()© MonKey ware
    Kyle J. R.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > done=0;
    >while(done)

    The loop won't execute because done is 0. Done should be 1 in order to execute it.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    43
    while(done) is now while(!done), but it still wont compile because of the toupper function. I get an error
    Code:
    [Type mismatch in parameter '__ch' in call to 'toupper']
    ()(ôô)()© MonKey ware
    Kyle J. R.

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    I think that's because toupper only converts one character at a time - you have to loop through the string and change every character indiviually.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    43

    Question

    How could I do that with out having the person type there name like:
    Code:
    printf("Enter the first letter of your name: ");
    scanf("%s",&first);
    first=toupper(first);
    printf("Enter the second letter of your name: ");
    scanf("%s",&second);
    second=toupper(second);
    so on......
    ()(ôô)()© MonKey ware
    Kyle J. R.

  8. #8
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Code:
    int i;
    
    for(i = 0;i<strlen(name);i++)
        name[i] = toupper(name[i]);

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    43

    Talking

    Thank you so much for all the help. It seems to work now.

    Again thank you.
    ()(ôô)()© MonKey ware
    Kyle J. R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  3. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 07:07 PM
  4. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM