Question:

Please help me w/ my proj. in c ..My prof told me to create a program that will output all 'a' in a word..

by Guest59376  |  earlier

0 LIKES UnLike

using array...

EXAMPLE:

Enter a word: answers

Output:

there is 1 a in word answer...

Using array, and my prof told me to use string.h

hope anyone could help because I dnt know yet how to use string.h

 Tags:

   Report

1 ANSWERS




  1. #include <stdio.h>

    #include <string.h>

    int main()

    {

      char szWord[500];

      int len,i;

      int charCount = 0;

      printf("Enter a word: ");

      fgets(szWord,499,stdin); //read up to 499 chars from

                               // standard input.

      len = strlen(szWord);    //use strlen in the string.h lib to get

                               // the zero terminated string length.

      for (i = 0; i < len; ++i)

      {

        if (szWord[i] == 'a') //count the number of a's

        {

          //increment your count here

        }

      }

      //output your answer here

      

      return 0;

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions