Thread: Program to Make nouns plural

  1. #1
    Registered User
    Join Date
    Nov 2010

    Program to Make nouns plural

    Hey guys..

    I'm writing a program that converts singular nouns to their plural form.
    ie.. if the noun ends in "y" remove the "y" and add "ies"
    ends in "s", "ch", or "sh" add "es"
    and any other case add "s"

    So i have my program listed below. I'm trying to remove the last character of the string, analyze it, then determine what action needs to take place. Does anyone have any other opinions on how to tackle this problem or any suggestion on what i've written so far?


  2. #2
    Registered User
    Join Date
    Nov 2010
    #include <stdio.h>
    #include <string.h>

    int main(void)
    char mystr[50] = {0}, tmp[50] = {0}, a[50]={0};
    int x;

    printf("Enter a string: ");
    printf("Last char: %c\n",mystr[(strlen(mystr)-1)]);
    tmp[x] = mystr[x];

    if((strlen(mystr)-1)= ' y ' ){
    else if(((strlen(mystr)-1)='s')){
    else if(((strlen(mystr)-1)='h')){
    printf("%ses", mystr);
    printf("%ss", mystr);
    return 0;

  3. #3
    Registered User
    Join Date
    Jan 2009
    You could just save the last character, once. Then overwrite it with '\0', your string will then be one character shorter and you wont need the temp array, or keep calling strlen().

    Then you could compare your saved character with a switch/case statement.

    Also, consider using fgets, instead of gets. This lets you restrict the input to 50 chars to make sure that no more than 50 chars will be written to your array.
    Last edited by Subsonics; 11-09-2010 at 06:50 PM.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Long Beach, CA
    Please use code tags (<< !! Posting Code? Read this First !! >>) when you post code in the future as well.

    You have a few substantial errors/misunderstandings to clear up:
    1. = is for assignment, == is for comparison
    2. strlen(mystr)-1 doesn't give you the last character, it simply gives you the index of the last character. The last character is mystr[strlen(mystr)-1], which you've determined already.

    Some general notes:
    What is the purpose of tmp and a? Do you ever use them or can you get rid of them?
    I suggest storing the length of mystr in a convenience variable, say "len". This will make your code more readable and more efficient (calling strlen is not free, it has to check every byte of the string every time).

    Also, I strongly suggest you try the following when you get around to testing your program. I think you will find a logical error your "ends in an h" check:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with this program I'm trying to make
    By Sshakey6791 in forum C++ Programming
    Replies: 14
    Last Post: 12-01-2008, 04:03 PM
  2. Replies: 9
    Last Post: 06-17-2008, 11:38 AM
  3. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  4. A doubt on how to make a program
    By louis_mine in forum C Programming
    Replies: 3
    Last Post: 08-20-2004, 11:16 AM
  5. How To Make The Program Installed In Program Files Folder?
    By javacvb in forum Windows Programming
    Replies: 4
    Last Post: 11-05-2003, 05:33 PM