I managed to open the file and read when writing to another file with var=fopen(file,"r") / "w" , but even with r + or w + moded I can not open the file and change its contents.
Imagine the following:
int formatacao (char original[]){ int val1; FILE * original_open; original_open = fopen (original,"r+"); if (original_open==0){ printf ("ficheiro %c 1.",original); } while ((val1=fgetc(original_open))!=EOF){ if (val1>='a'&&val1<='z'&&val1){ fputc(val1-32,original_open); } else fputc(val1,original_open); } fclose (original_open); return (0); }
The code works, no errors, no warnings, only the problem: it erases the contents in the file, if I use it like this, BUT it works:
int main (){ int val1,val2,nr=0; FILE* fp1; FILE* fp2; fp1=fopen ("DNAexample.txt","r"); fp2=fopen ("DNAexample1.txt","w"); if (fp1==0){ printf ("EPIC FAIL no 1.\n"); } while ((val1=fgetc(fp1))!=EOF){ if (val1>='a'&&val1<='z'&&val1){ fputc(val1-32,fp2); } else fputc(val1,fp2); } fclose (fp1); fclose (fp2); return (0); }
Impeccable! How to open a file, read char to char and decide if I want to change char or not?
source share