Thread: output file is a unicode file under certain circumstances

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    27

    output file is a unicode file under certain circumstances

    My program creates an output file based on the user's input. The user enters a pronoun, and the pronoun gets placed into the output file. Each time the program runs, the user enters additional pronouns which get appended to the output file. I noticed that whenever the user enters "i" as the first pronoun in the file, the file is a unicode file. Whenever the user enters any other pronoun, the file is an ANSI file. I need the files to consistently be ANSI files. What can i do to prevent files which begin with "i" from being unicode files?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Without seeing your code, or knowing which OS/Compiler you're using, how would we even make a guess?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    here is the code. i am using a c compiler provided by the Code Blocks program.

    Code:
    tensecomp = strncmp (past, tense, 2);
    verbcount = count;
    
    strncpy (filename2, username, length);
    strcat (filename2, "pasttenseverbs.txt");
    strncpy (filename5, username, length);
    strcat (filename5, "pronounp.txt");
    if (tensecomp ==0){
        outfile = fopen (filename5, "a");
            for (counter =0; answerfuture != 'n'; counter=counter +1){
            printf ("\n\nFor which pronoun did you learn past tense?");
            printf (" You may answer \ni for I\nyouf for you female\nyoum for you male\nhe for he\n");
        printf ("she for she\ntheyf for they female\ntheym for they males\nyoupg for you plural girls\nyoupb for you plural boys\n");
            scanf ("%s", & shemhagufp[counter]);
                comparison_vuv_f = strcmp ("theyf", shemhagufp[counter]);
                comparison_vuv_m = strcmp ("theym", shemhagufp[counter]);
                comparison_he_past = strcmp ("he", shemhagufp[counter]);
                comparison_she_past = strcmp ("she", shemhagufp [counter]);
                comparison_i_past = strcmp ("i", shemhagufp [counter]);
                if ((comparison_vuv_f==0) || (comparison_vuv_m ==0)|| (comparison_he_past ==0) || (comparison_she_past==0) || (comparison_i_past ==0) ){
                    printf ("Did you teach the VUV HAMEHAPEICH with this SHEM HAGUF ?\n Type y for yes and n for no.");
                    scanf (" %c", &vuvhamehapeich);
                        if (vuvhamehapeich=='y')
                        strcat (shemhagufp[counter], "and");
                        printf ("%s\n", shemhagufp[counter]);
                    }
            fprintf (outfile, "%s ", shemhagufp[counter]);
            printf ("\ndo you want to enter another shemhaguf?");
            printf ("\nenter y for yes and n for no.\n Use lowercase only.\n");
            scanf (" %c", &answerfuture);
                        }
            fclose (outfile);
    }
    THANKS!

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    If your user puts an "i" as the first character, it will put "i " (trailing space) into the first position in the file... but that doesn't make it unicode. In a unicode file, containing the english alphabet every second byte will be a 0, not a space.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    >What can i do to prevent files which begin with "i" from being unicode files?
    Verify that you can create such a file with a real simple 5-line program.
    - open file
    - write "i"
    - close the file
    Is it a UNICODE file?

    If not, there is some weirdness in your code, and nothing to do with the actual content.

    I notice that you're using strn functions in some places. Note that these do not automatically append a \0, so you might have trailing garbage which might be interpreted as being UNICODE.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IDE for C embedded advanced editing
    By Undici77 in forum Tech Board
    Replies: 32
    Last Post: 01-16-2010, 05:17 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM