Hi
Can someone find out what is wrong? Program reads input from the keyboard and should replace some strings that are found in 'opmaak.txt' I found that the Content of 'Kode' changes when something is put into 'Vervang'
Somebody know what I'm doing wrong?
My code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main(void)
{
int intikken(void);
char vervangen(char string[255]);
int sw=0, swM;
while(sw==0)
{
printf("MENU:\n 1.Tekst intikken\n 2.Afsluiten\nNummer: ");
scanf("%d",&swM);
switch (swM)
{
case 1 : intikken();
break;
case 2 : sw = 1;
break;
default : clrscr();
printf("Foute Code!\n");
break;
}
}
return 0;
}
int intikken(void)
{
char zin[255], res[255], temp[255];
char Kode[10], Vervang[10];
char stop[]="stop";
char c, *pos;
FILE *fOpmaak;
FILE *fInput = fopen("input.txt","w");
printf("Tik zinnen in: \n");
scanf("%[^\n]%c",&zin,&c);
while(strcmp(zin,stop)!=0)
{
fOpmaak = fopen("opmaak.txt","r");
while(!feof(fOpmaak))
{
//here it goes wrong :(
fscanf(fOpmaak,"%[^\n]%c",&Kode,&c);
fflush(stdin);
fscanf(fOpmaak,"%[^\n]%c",&Vervang,&c);
do
{
pos = strstr(zin,Kode);
if(pos != NULL)
{
strncpy(res,zin,(strlen(zin)-strlen(temp)));
strcat(res,Vervang);
sprintf(temp,"%s",pos+strlen(Kode));
strcat(res,temp);
strcpy(res,zin);
}
}while (pos!= NULL );
fclose(fOpmaak);
}
fprintf(fInput,"%s\n",zin);
scanf("%[^\n]%c",&zin,&c);
}
fclose(fInput);
return 0;
}
Opmaak.txt could look like this:
Code:
[B ]
\33\50\163\63\102
[/B ]
\33\50\163\60\102
[I ]
\33
[/I ]
\33
[U ]
\33\46\144\61\104
[/U ]
\33\46\144\100