help can't find a way to make this work
hi, I'm doing a very simple program in which I want to remove comments from a .c file, so I started with something simple and tried to make a program that changed ' ' to a '.' except that I can't make it work, every time the program finds a ' ' it ends the search cycle and the '.' is somehow written at the end of the file. :S It must have a very simple solution please help.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *file;
int o = 1;
void time()
{
int i;
for(i=0; i<10000000; i++);
}
void commentremover(FILE *tmp)
{
char o;
int i = 0;
char input[] = ".";
//FILE *tmp2;
//tmp2=tmp;
while((o=fgetc(tmp)) != EOF)
{
if(o=='\n')
{
printf(" %d \t:*LF*:\n", i , o);
}
else
{
if(o=='\x0D')
{
printf(" %d \t:*CR*:\n");
}
else
{
if(o==' ')
{
fwrite(input,1,1,tmp);
}
else
{
printf(" %d \t:%c:\n", i , o);
}
}
}
i++;
fflush(stdout);
}
}
void printer(FILE *tmp)
{
char o;
o = fgetc(tmp);
while(o != EOF)
{
time(1);
printf("%c", o);
o = fgetc(tmp);
}
}
int main()
{
file = fopen("out.txt", "r+");
commentremover(file);
return 0;
}
edit: The printf sequence is part of the 'seach throu the file bit' they will be removed after I get the writing working