Wrox Programmer Forums
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 3rd, 2006, 11:06 AM
Registered User
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

I need to write a program that

a. takes a text file as input (i know i can use fopen with this)

b. modifies the contents of the text file and creates a separate file (it means i have to have another file, the formatted one and must have a different filename) with the ff features
- all words at the start of the sentence should be capitalized.
- additional blank spaces should be removed.

c. also prints the statistics in the text of the number of characters, words and sentences. (i have a knowledge here... i must have a counter for each...)

please help me... thanks![/font=Arial][/size=3][/size=1]
Reply With Quote
  #2 (permalink)  
Old March 5th, 2006, 04:14 PM
Authorized User
Join Date: Oct 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to C@uark

yeah you could use fopen to open the file, fgetc to read charcters from, do what ever with, then use fprintf to create and copy the orginals files changed contents. make sure to use fclose to view new file
Reply With Quote
  #3 (permalink)  
Old March 13th, 2006, 02:57 PM
Registered User
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Here is a File handling programme might be of your interest.
It contains a program that is given as command parameter the name of a text file, say, temp.dat. It will read each line of temp.dat and print out in correspondence the number of characters and words on that line. At the end it will print out the number of lines that were read....

#include <stdio.h>

int main (int argc, char *argv[]){
  FILE *fp;
  int nchars, nwords, nlines;
  int lastnblank; /* 0 iff the last character was a space */
  char c;

    printf("Usage: %s filename\n", argv[0]);
    if (c=='\n'){
      if (lastnblank)
      printf("words=%d, characters=%d\n", nwords, nchars);
      if (((c==' ')||(c=='\t'))&(lastnblank))
      lastnblank=((c!=' ')&&(c!='\t'));
  printf("lines=%d\n", nlines);

If you dont know hot to Program come to
Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
here is my code c++ file handling amahja56 C++ Programming 2 November 23rd, 2007 07:25 AM
File strorage handling using JSP draggy Pro JSP 4 July 30th, 2006 12:44 PM
File handling vijayma VB How-To 3 June 7th, 2006 01:30 AM
c++ file handling. amahja56 C++ Programming 2 March 23rd, 2005 07:13 PM
FILE HANDLING sanchita ADO.NET 8 November 8th, 2004 12:34 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.