Nu skulle den være en smuk kode
Men kan ikke helt finde ud af det der pre-postcondition, ved ik hvad jeg skal skrive for de forskellige funktioner.
Ved godt du igår sagde at det giver sig selv, gør det desværre ikke her
#include <stdio.h>
#include <stdlib.h>
void fileconverterEt(char inputfil[], char outputfil[])
//precondition: inputfil og outputfil peger på tildeldte værdier.
/*postcondition: Værdierne som inputfil og outputfil peger på,
at blive sat til funktionkaldelse fopen.*/
{
FILE *pt1, *pt2;
char ch, lastCh = 0;
pt1 = fopen(inputfil,"r");
pt2 = fopen(outputfil,"w");
while((ch = fgetc(pt1)) != EOF) //end of file
{
if(ch == '.')
{
ch = ',';
}
if(ch == ' ' && lastCh == ' ')
{
}
else
{
fprintf(pt2,"%c",ch);
}
lastCh = ch;
}
fclose(pt1);
fclose(pt2);
}
void fileconverterTo(char inputfilTo[], char outputfilTo[])
//precondition:
//postcondition:
{
FILE *pt2, *pt3;
char ch, lastCh = 0;
pt2 = fopen(inputfilTo,"r");
pt3 = fopen(outputfilTo,"w");
while((ch = fgetc(pt2)) != EOF)
{
if(ch == ' ')
{
ch = ';';
}
fprintf(pt3,"%c",ch);
}
fclose(pt2);
fclose(pt3);
}
void fileconverterTre(char inputfil[], char outputfil[], char TegnEt, char TegnTo)
//precondition:
//postcondition:
//Forudsat at indputfilen kun indeholder et skilletegn mellem dataerne.
{
FILE *pt1, *pt2;
char ch, lastCh = 0;
pt1 = fopen(inputfil,"r");
pt2 = fopen(outputfil,"w");
while((ch = fgetc(pt1)) != EOF)
{
if(ch == TegnEt)
{
ch = TegnTo;
}
if(ch == TegnEt && lastCh == TegnEt)
{
}
else
{
fprintf(pt2,"%c",ch);
}
lastCh = ch;
}
fclose(pt1);
fclose(pt2);
}
void fileconverterFire(char inputfil[], char outputfil[])
{
FILE *pt1, *pt2, *temp1, *temp2;
char ch, lastCh = 0;
pt1 = fopen(inputfil,"r");
pt2 = fopen(outputfil,"w");
temp1 = fopen("temp1.txt","w");
while((ch = fgetc(pt1)) != EOF)
{
if(ch == ' ' && lastCh == ' ')
{
}
else
{
fprintf(temp1,"%c",ch);
}
lastCh = ch;
}
fclose(temp1);
fclose(pt1);
temp1 = fopen("temp1.txt","r");
temp2 = fopen("temp2.txt","w");
while((ch = fgetc(temp1)) != EOF)
{
if(ch == ' ' && lastCh != ' ')
{
fprintf(temp2,"%c\n",ch);
}
else
{
fprintf(temp2,"%c",ch);
}
lastCh = ch;
}
fclose(temp1);
fclose(temp2);
temp2 = fopen("temp2.txt","r");
while((ch = fgetc(temp2)) != EOF)
{
if(ch == '.')
{
ch = ' ';
}
if(ch == ' ' && lastCh == ' ')
{
}
else
{
fprintf(pt2,"%c",ch);
}
lastCh = ch;
}
fclose(temp2);
fclose(pt2);
}
int main()
{
fileconverterEt("input.txt", "output.txt");
fileconverterTo("output.txt", "outputTo.txt");
fileconverterTre("InputfilTre.txt", "OutputfilTre.txt", '-', ' ');
fileconverterFire("input.txt", "outputFire.txt");
system("PAUSE");
return 0;
}