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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Converting

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can some tell me what i can use to read a text document and convert all occurance of ";" to "/".

I can read the file using fscanf() fgetc but cannot convert ";".

Text file has years and events as below.

1966 England won world cup; dgfgsgggd.
2002 New world cup game; all invited.

to read this i am using the command
int year;
char event [300];
year = fscanf (fp,"%f%",&year);
fgets(event,300,fp);

tried!
if (event = ';'){
event = '/';
else event = event; }

did not work, what i must do is to read character by character and do covert if ';' found to '/'.

I tried doing so with other command but no luck.

please help!!
 
You could read the file char by char, but if it's a normal text file with lines it would be quicker to read the lines and replace the chars with a simple loop, like

void cvtFile()
{
char buff[1024];
FILE *fin = fopen("c:\\test.txt","r");
FILE *fout = fopen("c:\\test1.txt","w");
if (fin && fout)
{
// read and convert lines
while(!(feof(fin) || ferror(fin) || ferror(fout)))
{
fgets(buff,1024,fin);
char *bp = buff-1;
while(*++bp) if (*bp==';') *bp = '/';
fputs(buff,fout);
}
}
fclose(fin);
fclose(fout);
}
:) I just can't help it, I like MS...:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top