programming9
  • Flowcharts
  • Programs
      • Back
      • C Programs
      • C++ Programs
      • Java Programs
      • Python Codes
      • HTML Codes
      • Java Script Codes
      • SQL Codes
  • Tutorials
      • Back
      • Java Tutorials
      • Competitive Programming
      • Python Tutorials
      • C Programming
  • Blog
  • Login

C Program to Find Number of Characters and Words in a String

Details
Written by: RajaSekhar
Category: C Programs
  • C Strings
#include <stdio.h>
#include <string.h>
int main()
{
    char str[50];
    int i=0, word=0, chr=0;
    printf("\nEnter Your String: ");
    gets(str);
    while (str[i] != '\0')
    {
        if (str[i] == ' ')
        {
            word++;
            chr++;
        }
        else
            chr++;
        i++;
    }
    printf("\nNumber of characters: %d", chr);
    printf("\nNumber of words: %d", word+1);
    return 0;
}

 OUTPUT:

Enter Your String: Welcome to Programming9 .com

Number of characters: 28
Number of words: 4

Previous article: C Program to Find Length of a String Using STRLEN() Prev Next article: C Program to Copy Contents From One File to Another Next
  • C Program for Multiplication Table using Goto Statement
  • C program to find Sum of Digits of a Positive Integer Number
  • C Program for Arithmetic Operations using Switch Statement
  • C Program to Calculate Sum of Odd Values in an Array
  • C Program to Find Address Locations of Variables
  • C Program to Solve Sum of Series 1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!
  • C Program for Implementation of Predictive Parser
  • C Program to Find Given Integer is Positive or Negative
  • C Program to Print ASCII values of Characters
  • C Program to Delete Characters from Given String
  • Check a Character is Vowel or not Using C
  • C Program to Find Nth Fibonacci Number Using Recursion
  • C Program to Print Pyramid of Numbers
  • C Program to Convert Temperature from Degree Centigrade to Fahrenheit
  • C Program to Find Second Largest Number in an Array
  • Privacy Policy
  • Cookie Policy
© programming9.com 2025
Back to top