Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone please help

Status
Not open for further replies.

ioman

IS-IT--Management
Feb 4, 2005
3
US
I wrote a VC++5.0 program to read a text file, amend it and save it again with different name, all works fine but i have a problem, the text file i am reading is in Capital letters, can someone please help me or guide on how to convert the text into lower case letters and ignor words like CID, TV etc ie.

from : THE CID TV GAME
to: The CID TV Game ( all first letters to be in Caps and the rest in lower case)

PLease Help
 
Well you first need to make a list of words that you dont want to capitalize. I would approach it as a struct

struct KeepCapitol
{
CString lower;
CString upper;
}

then I would Initialize the struct as follows

KeepCapitol kc[] = {
{"tv","TV"},
{"cid","CID"}
};

I would then read the whole thing into a CString buffer and call ToLower on it.

After it was ALL lowercase I would then call the Replace method of CString as:

csBuffer.Replace(kc[0].lower,kc[0].upper);

The array makes it easy to do this in a for loop.

Matt
 
Thanks Zyrenthian,
I tried your code with my program but got few errors, i tried help in VC++ on _tolower and still cannot get it to work.
There what i have so far..

#include <stdio.h>
#include <afx.h>
#include <Ctype.h>
#include <String.h>
#include <conio.h>


int main()
{

struct KeepCapital
{
CString lower;
CString upper;
};

KeepCapital kc[]={ {&quot;tv&quot;,&quot;TV&quot;},{&quot;cid&quot;,&quot;CID&quot;}};

FILE *fp, *fp1; // file pointer

int nTimeFlag=0; // time flag
float nTmpTime=0.00; // ref time.
char fname[80];

printf(&quot;File name to convert: &quot;);
scanf(&quot;%s&quot;,fname);

/* Open file for reading (fail if data does not exist) */
if( (fp = fopen(fname, &quot;rt&quot; )) == NULL )
printf( &quot;error opening file \n&quot; );
else
printf( &quot;file opened \n&quot; );

fp1 = fopen(&quot;pec.txt&quot;,&quot;wt&quot;);

// store original time in array time
while (!feof(fp))
{
float nTime;
char szBuf[10];

int nRet = fscanf(fp,&quot;%f&quot;,&nTime);
if (nRet == -1) break;
fgets(szBuf,10,fp);
_tolower(szBuf );

*/ // write converted time(2dp) and text to new file

fprintf(fp1,&quot;%.2f %s\n&quot;,nTmpTime,szBuf);


}

fclose(fp);
fclose(fp1);
return 0;
}

i am getting error on initialize KeepCapital ( cannot conver fromchar[3] /[4])

Help..

 
Lost Track,
Some1 please help with above....
 
You should give a length for kc and init it explicitly:
KeepCapital kc[2];
kc[0].lower= &quot;tv&quot;;
kc[0].upper= &quot;TV&quot;;
etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top