1

The Situation: I'm trying to create this little program to store short messages,notes, etc.. in alert windows in order just to display them simply clicking the .vbs file.

The Issue: Everything perfectly works exactly how I want, except when I write a message with accented characters in the DOS window which runs the compiled progam (i'm using Dev-C++).

All the accented characters are displayed correctly, but when I write them into the notepad (using fprintf) all the accented characters become other characters (such as "•…Šss—" ).

Could somebody help me? Is there a c++ function to translate the accented characters in a way notepad can understand correctly?

The Code:

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<locale.h>

int main () {
setlocale (LC_ALL,"UTF8");
FILE *puntafile;
char c, nome[30];

//Choosing file name
printf("Insert file name (Max 25 characters): ");
gets(nome);

while(strlen(nome) > 25)
 {
    printf("Too much long name!\n");
    printf("Insert file name (Max 25 characters): ");
    gets(nome);
 } 

//creation file name .vbs
char est[4];
strcpy (est,".vbs");
strcat (nome,est);

char testo[100];

//create the empty file
puntafile = fopen(nome,"w+");

//Insert the message
printf("Insert the note text (Max 100 characters): ");
gets(testo);

while(strlen(testo) > 100)
 {
    printf("Too much long text!\n");
    printf("Insert the note text (Max 100 characters): ");
    gets(testo);

 } 

//writing in the file...
char note[150];

//start text
strcpy(note,"msgbox \"");

//add the note text
strcat(note,testo);

//ending text
char closing[20];
strcpy(closing,"\" , \"6\" , \"Note\"");
strcat(note,closing);    

//writing all in the .vbs file  
fprintf(puntafile,"%s",note);


//end and close
printf("Note created!\n");
fclose(puntafile);
system("PAUSE");
}
Newd
  • 2,174
  • 2
  • 17
  • 31

1 Answers1

0

The most probable cause is that there's a different encoding used by Notepad and the command line. There's a long article about it and how to resolve this issue: What encoding/code page is cmd.exe using?

Community
  • 1
  • 1
psliwa
  • 1,094
  • 5
  • 9
  • I let my program write the code to show the msgbox directly in the ".vbs" file, so I'm wondering if there is a command line that i should write before the msgbox to change the charset to utf-16 when i create the file, i tried with the "SetConsoleOutputCP" function, but it doesn't work. – Gaetano Brancato Jun 30 '15 at 16:26