Write an algorithm and implement a program in C to read the data from a
file (called “test.txt”), transform the data according to the discussion in
“Introductory”, and afterwards, save in another file (called “final.txt”).
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//define funcion for transformation
void doTranform(char *str)
{
//For example do evere lowercase to uppercae letter
for(int i=0;i<strlen(str);i++)
{
str[i]=toupper(str[i]);
}
}
int main(void) {
FILE *finp=fopen("test.txt","r+");
FILE *fout=fopen("final.txt","w+");
char line[100];//each line save to this id
//will read use getline functio
while(fgets(line,100,finp))
{
doTranform(line);
fputs(line,fout);//write to file
}
fclose(finp);
fclose(fout);
return 0;
}
Comments
Leave a comment