lynes_anthony_program2.c - void plural(char word...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* *Anthony Lynes *Program 2, CSCI112 *4/6/16 */ #include <stdio.h> #include <string.h> #include <stdlib.h> #define SIZE 20 //define size to be 20 /*function prototypes*/ void plural( char word[]); void get_input( char * ); /*program entry point*/ int main (int argc, char * argv[]) { char plural_string[SIZE] = {0}; /*checks for correct number of args*/ if(argc >= 2) { int i; for(i=1; i<argc; i++) { printf("noun: %s\n",argv[i]); strncpy(plural_string, argv[i], SIZE); plural(plural_string); printf("plural: %s\n\n", plural_string); } } else { /* if program not executed correctly, error displayed */ printf("ERROR: You must pass the nouns to be pluralized as program arguements\n"); } return 0;//exits program after either outcome } /* Purpose of this function is to take the string and concatenate it. This can be done using strcat strcpy and strlen
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: */ void plural(char word) { /* declarations */ int length; /* find length of word */ length = strlen(word); /* check first rule: if word ends in "y" then change to "ies" */ if (word[length - 1] == 'y') { word[length - 1] = 'i'; word[length] = 'e'; word[length + 1] = 's'; word[length + 2] = '\0'; // put '\0' at end of string } /* check second rule: if word ends in "s" "ch" or "sh" add "es" */ else if (word[length - 1] == 's' || (word[length - 2] == 'c' && word[length - 1] == 'h') || (word[length - 2] == 's' && word[length - 1] == 'h')) { /* concatenate "es" to word */ strcat(word, "es"); } /* otherwise, just add "s" to the end of word */ else { /*concatenates s to the end of the string */ strcat(word, "s"); } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern