Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. C Programming

String Counting

Book navigation

  • C Programming Introduction
  • C – Program Code – Basics Part I
  • C – Program Code – Basics Part II
  • Operators in C Programming
  • C – Program Code – Basics Part III
  • C Program Code Basics - Part IV
  • Addition , Subtraction and Multiplication of Matrices
  • Solving Quadratic Equation
  • Sum of sin series
  • Sum of cos series
  • Sum of e series
  • Ascending and Descending order
  • Sorting in Alphabetical Order
  • Factorial of a number
  • Fibonacci Series
  • String Counting
  • String Manipulation
  • Bisection Method
  • Newton Raphson Method
  • Lagrange's Interpolation
By Karthikeyan , 8 September, 2009

Sample C Program to counter number of words and lines


#include
#include
#include
char c;
main()
{
	char c, str[200];
	int i =0;
	clrscr();
    printf("\n\t\t String counting");
    printf("\n\t\t ***************");
    printf("\n Enter a String and terminate it with * star\n");
    do
    {
        c=getchar();
        str[i++]=c;
    }
    while(c!='*');
    count(str);
}
count(char *s)
{
    int l=1, w=1;
    printf("\n The given strings: \n");
    while(*s != '*')
    {
        printf("%c", *s);
        if(*s == ' ')
        w++;
        if(*s == '\n')
        {
            if(c != ' ')
            w++;
            c = *s;
            l++;
        }
        s++;
    }
    if(w ==0 && l ==0)
    {
        printf("\n There is one word and one line");
        exit();
    }
    if(l ==0)
    l=1;
    printf("\n There are %d words and %d lines", w,l);
    printf("\n\t *****************************");
    getch();
}

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy