I'm with CommonTater, two files should be used. here is some code that will read, find and replace, then remove the input file and rename the output file to the input.
Disclaimer: i haven't tested this yet. Correct me if i'm wrong
Code:
#include <stdio.h>
int main(int argc, char** argv) /* you don't need these args, but i like putting them in regardless */
{
char line[255]; /* or however long you want */
FILE* in = fopen("file2.txt", "r");
FILE* out = fopen("_file2_.txt", "w");
if (in == NULL)
{
printf("File access error.\n");
return 0;
}
while(fgets(line, sizeof line, INSTREAM) != NULL) /* if you only have 1 line, you can comment this out, but if the file contains multiple lines, leave this in */
{
for(i = 0; line[i] != NULL; i++)
{
if (line[i] == "#") /* finds "#" */
{
fprintf(out, "%c", "*"; /* writes "*" */
}
else
{
fprintf(out, "%c", line[i]); /* writes the letter that isn't "#" */
}
}
}
fclose(in); fclose(out);
remove("file2.txt"); /* deletes the input file */
rename("_file2_.txt", "file2.txt"); /* names the output file, what the input file was */
return 0;
}