Hello! I need to write a program that reads char by char, deletes spaces and hyphenation in front of dots and commas in text file. Then I need to put the edited text in another file. I wrote a program that removes a single space/hyphen, but how do I remove several of them? The use of string.h and other libraries except standard lib is forbidden!
Help a noob, I need this for tomorrow!
Code:
#include <stdio.h>int main(int argc, char *argv[])
{
FILE *f1;
FILE *f2;
char ch1;
char ch2;
if(argc==1)
{
printf("File is unknown\n");
return 1;
}
f1=fopen(argv[1], "r");
if(!f1)
{
printf("Error opening %s\n", argv[1]);
return 2;
}
f2=fopen(argv[2], "w");
if(!f2)
{
printf("Error creating %s\n", argv[2]);
return 3;
}
while((ch1=getc(f1))!=EOF)
{
if((ch1==' ')||(ch1=='\n'))
{
if((ch2 = getc(f1))=='.')
{
fputc('.', f2);
}
else
{
fputc(ch1, f2);
fputc(ch2, f2);
}
}
else fputc(ch1, f2);
}
printf("The editing is complete!");
return 0;
}
The code should remain analtered higher than first while loop.