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
  • Swapping of Two Numbers Using Call By Reference in C
  • C Program for Quick Sort
  • C Program to Print PRIME Numbers in a Given Range
  • C Program to Find Area of a Triangle
  • C Program to Find Given Number is Perfect or Not
  • C Program Example for Call By Reference
  • C Program to Find Address locations of Array Elements Using Pointers
  • C Program for Matrix Multiplication
  • C Program to Find Prime Factors of a Given Positive Number
  • C Program to Evaluate POSTFIX Expression Using Stack
  • C Program to Search an Array Element using BINARY SEARCH
  • C Program to Print Elements of Array Using Pointers
  • C Program to Copy a String with out using strcpy() Built in Function
  • C Program to Find Second Largest Number in an Array
  • C Program to Print Prime Numbers upto a given Number
  • Privacy Policy
  • Cookie Policy
© programming9.com 2025
Back to top