/* Tanel Toova * 8-1 */ #include #include #include #include #include #define NEWSFILE "/tmp/newsline.txt" int main(void) { FILE * fNews; //Array used to replace characters char *Amass[]={"Ä","ä","Ö","ouml;","Õ","õ","Ü","ü"}; //Array used to check characters char Vmass[8]={'Ä','ä','Ö','ö','Õ','õ','Ü','ü'}; int iChar; int i; int olemas; //if "olemas"=1 then character already replaced and sent to stdout fNews = fopen(NEWSFILE, "r"); //header printf("Content-Type: text/html\r\n\r\n"); printf("\n"); printf("\n"); printf("NewsLine\n"); printf("\n"); printf("\n"); printf("
\n
NewsLine
\n
\n"); if(!fNews){ printf("Error opening news file\n"); } else{ while((iChar = getc(fNews)) != EOF){ olemas=0; //it's assumed that character does not need to be replaced for(i=0;i<8;i++){ //checking if character needs to be replaced if((char)iChar==Vmass[i]){ fprintf(stdout,"%s",Amass[i]); olemas=1; } } if((char)iChar==10){ //if eol is needed fprintf(stdout,"
"); olemas=1; } if(olemas==0){putc(iChar,stdout);} //if character was not replaced put it to stdout } fclose(fNews); } printf("
\n"); printf("\n"); printf("\n"); return 0; }