Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C language

C language

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
3 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavani M
    wrote on last edited by
    #1

    Write a C program to Count the Lines, Words and Characters in a given text *Write a C program to count the lines, words and characters in a given text. *At the time of execution, the program should print the following message on the console as: *Enter lines of text (enter END to complete) For example, if the user gives the input as: Enter lines of text (enter END to complete) CodeTantra developed a Robotic tool In the year 2016 END then the program should print the result as: Character = 51, Words = 9, Lines = 2 Note: Do use the printf() function with a newline character (\n) at the end

    L CPalliniC 2 Replies Last reply
    0
    • P Pavani M

      Write a C program to Count the Lines, Words and Characters in a given text *Write a C program to count the lines, words and characters in a given text. *At the time of execution, the program should print the following message on the console as: *Enter lines of text (enter END to complete) For example, if the user gives the input as: Enter lines of text (enter END to complete) CodeTantra developed a Robotic tool In the year 2016 END then the program should print the result as: Character = 51, Words = 9, Lines = 2 Note: Do use the printf() function with a newline character (\n) at the end

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This is your assignment, so you are expected to do the work. If you do not understand the assignment then you need to ask your teacher for guidance.

      1 Reply Last reply
      0
      • P Pavani M

        Write a C program to Count the Lines, Words and Characters in a given text *Write a C program to count the lines, words and characters in a given text. *At the time of execution, the program should print the following message on the console as: *Enter lines of text (enter END to complete) For example, if the user gives the input as: Enter lines of text (enter END to complete) CodeTantra developed a Robotic tool In the year 2016 END then the program should print the result as: Character = 51, Words = 9, Lines = 2 Note: Do use the printf() function with a newline character (\n) at the end

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        Read a line, fgets[^] is your friend. If the line read is exactly END than your task is complete: report the line, word and character count. On the other hand, if the line read is not the termination one, then increment the line count, and get the first character (incrementing the character count): if it is a blank then set a flag was_blank = 1; and go on. If it is not a blank then increment the word count and clear the flag: was_blank = 0;. Go on with the next character (if any): increment the character count and if the character is

        • a blank then set was_blank = 1;

        • not a blank then, depending on the was_blank flag increment the word count (or do nothing), eventually clear the flag: was_blank = 0;

          "In testa che avete, Signor di Ceprano?" -- Rigoletto

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups