I have a UTF-8 text file containing several characters that I would like to change with others (only those that were between | (and |)), but the problem is that some of these characters are not considered characters, but as multi-character signs. (By this I mean that they cannot be placed between "∞", but only as "∞", so char *?)
Here is my text file:
Text : |(abc∞∪v=|)
For instance:
∞ should be changed with ¤c
∪ by ¸!
= changed to "
Since some characters (∞ and ∪) are multi-characters, I decided to use fscanf to get the whole text word for word. The problem with this method is that I have to put a space between each character ... My file should look like this:
Text : |( a b c ∞ ∪ v = |)
fgetc cannot be used because characters like ∞ cannot be considered as one single character. If I use it, I will not be able to strcmp a char with each character (char *), I tried to convert my char to char *, but strcmp! = 0.
Here is my C code to help you understand my problem:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void){
char *carac[]={"∞","=","∪"};
FILE *flot,*flot3;
flot=fopen("fichierdeTest2.txt","r");
flot3=fopen("resultat.txt","w");
int i=0,j=0;
char a[1024];
while(!feof(flot))
{
fscanf(flot,"%s",&a[i]);
if (strstr(&a[i], "|(") != NULL){
j=1;
fprintf(flot3,"|(");
}
if (strcmp(&a[i], "|)") == 0)
j=0;
if(j==1) {
if (strcmp(carac[0], &a[i]) == 0) { fprintf(flot3, "¤c"); }
else if (strcmp(carac[1], &a[i]) == 0) { fprintf(flot3,"\"" ); }
else if (strcmp(carac[2], &a[i]) == 0) { fprintf(flot3, " ¸!"); }
else fprintf(flot3,"%s",&a[i]);
}
else {
fprintf(flot3, "%s", &a[i]);
fprintf(flot3, " ");
}
i++;
}
}
Thank you very much for your help in the future!
EDIT: Each character will be correctly changed if I put a space between them, but without it it will not work, which I am trying to solve.