#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Kragujevac
    Posts
    1
    Rep Power
    0

    Question Character libraries


    I recently created a program that is supposed to write a random line from choosen one of five files. The program works but instead of some characters(these are the characters I'm having problems with , , ) it writes a bunch of others, can anyone help me fix this? Do I need to include some special library to be able to write them?
    Here's the code(all the functions are the same they just write from diffrent files):


    #include<stdio.h>
    #include<string.h>
    #include<dos.h>

    void output()
    {
    int size = 0,b;
    char peeps[10000][1];
    FILE *people = fopen("imenices.txt","r");
    while(fscanf(people,"%s",peeps[size]) != EOF)
    {
    ++size;
    }
    fclose(people);
    peeps[size][1];
    srand(time(NULL));
    b=rand()%1;
    printf("%s\n",peeps[b]);
    size=0;
    char peeps1[10000][1];
    FILE *people1 = fopen("imenicen.txt","r");
    while(fscanf(people1,"%s",peeps1[size]) != EOF)
    {
    ++size;
    }
    fclose(people1);
    peeps1[size][1];
    system("pause");
    printf("%s\n",peeps1[b]);
    }
    void pridevi()
    {
    int size = 0,b;
    char peeps[10000][10];
    FILE *people = fopen("pridevis.txt","r");
    while(fscanf(people,"%s",peeps[size]) != EOF)
    {
    ++size;
    }
    fclose(people);
    peeps[size][10];
    srand(time(NULL));
    b=rand()%10;
    printf("%s\n",peeps[b]);
    size=0;
    char peeps1[10000][10];
    FILE *people1 = fopen("pridevin.txt","r");
    while(fscanf(people1,"%s",peeps1[size]) != EOF)
    {
    ++size;
    }
    fclose(people1);
    peeps1[size][10];
    system("pause");
    printf("%s\n",peeps1[b]);
    }


    void pglagoli()
    {
    int size = 0,b;
    char peeps[10000][1];
    FILE *people = fopen("pglagolis.txt","r");
    while(fscanf(people,"%s",peeps[size]) != EOF)
    {
    ++size;
    }
    fclose(people);
    peeps[size][1];
    srand(time(NULL));
    b=rand()%1;
    printf("%s\n",peeps[b]);
    size=0;
    char peeps1[10000][1];
    FILE *people1 = fopen("pglagolis.txt","r");
    while(fscanf(people1,"%s",peeps1[size]) != EOF)
    {
    ++size;
    }
    fclose(people1);
    peeps1[size][1];
    system("pause");
    printf("%s\n",peeps1[b]);
    }


    void nglagoli()
    {
    int size = 0,b;
    char peeps[10000][69];
    FILE *people = fopen("nglagolis.txt","r");
    while(fscanf(people,"%s",peeps[size]) != EOF)
    {
    ++size;
    }
    fclose(people);
    peeps[size][69];
    srand(time(NULL));
    b=rand()%69;
    printf("%s\n",peeps[b]);
    size=0;
    char peeps1[10000][69];
    FILE *people1 = fopen("nglagolin.txt","r");
    while(fscanf(people1,"%s",peeps1[size]) != EOF)
    {
    ++size;
    }
    fclose(people1);
    peeps1[size][69];
    system("pause");
    printf("%s\n",peeps1[b]);
    }



    int main()
    {
    int e=0;
    printf("Uneti opciju 1/2/3/4/5\n");
    printf("1-imenice\n");
    printf("2-pridevi\n");
    printf("3-pravilni glagoli\n");
    printf("4-nepravilni glagoli\n");
    printf("5-izlaz\n");
    while(e!=27)
    {
    int o;
    scanf("%d",&o);
    switch (o)
    {
    case 1:
    output();
    break;
    case 2:
    pridevi();
    break;
    case 3:
    pglagoli();
    break;
    case 4:
    nglagoli();
    break;
    case 5: e=27;
    }
    }
    return 0;
    }
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,114
    Rep Power
    1803
    I cannot actually see where in amongst all that unformatted code you are attempting to print these characters. The problem is rather simpler that the ammount of code you have posted warrants - perhaps you could post just the code that is problematic, or a smaller example that reproduces the specific problem. Either way, do post in code tags to preserve formatting.

    Anyhow, what you need to realise is that a Win32 console does not use Unicode like your GUI editor probably does, so cannot display all the characters in any particular Unicode set. Win32 consoles use an 8 bit character set where the characters above 127 vary depending on the regional settings of the machine the code is running on (specifically the code page). Moreover, a user may set the console to use either the default bit-mapped terminal font or any monospaced truetype font; while the true type font may be Unicode, the console will only display characters with codes below 256, and the characters from 128 to 255 may differ from the corresponding characters in the default terminal font.

    In short attempting to display non-ASCII subset characters in a Win32 console is fraught with issues and best avoided. You will need to write a GUI app, or at least a graphical app that uses GDI text rendering and Unicode.

    On a US installation of Windows (and possibly some others):

    = character code 145 (0x91)
    = not supported
    = 134 (0x86)

    Example:

    Code:
    printf( "\x91 \x86" ) ;
    Your mileage may vary. And it may or may not work on any other WIndows installation. For a table of US console extended characters see http://www.asciitable.com/.

IMN logo majestic logo threadwatch logo seochat tools logo