简体   繁体   中英

Program Leaves Loop Too Early

I am working on a program that reads from a UTF-8 Text file, gets the Unicode value of each character, and then outputs the Unicode language block that is seen most frequently in the text file.

As of now, when reading through the text file, the program only makes it through 16 iterations before exiting the loop, but there are a lot more than 16 characters.

Here is the loop I am talking about:

for(int i = 0; fgets((char *) sampleText, 3000, fp) != NULL; i++)
    {
        int temp;
        temp = utf8_to_codepoint(&sampleText[i], &lenptr);
        printf("%d\n", temp);
        printf("i: %d\n", i);
        for(int k = 0; k < unicodeData[0].languagecount; k++)
        {
            if(temp <= unicodeData[k].max && temp >= unicodeData[k].min)
            {
                unicodeData[k].numChars++;
            }
        }
    }

When i is printed, it caps out at 16. As for temp, some of the values seem to be correct. I don't know if this is a simple issue or a complicated one, so I will post the full code below, followed by sample.txt (the text file I am reading from), followed by the output, followed by blocks.txt (which is used for the unicode values) in case someone needs to reference it.

AlphabetRecognition.c

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

    #include "utf8.h"

    //***USED TO STORE DATA ABOUT EACH UNICODE BLOCK***\\
    typedef struct{
            int max;
            int min;
            int languagecount;
            int numChars;
            char lang[300];
            //Contains a string holding hex ranges and a language.
            char lineinfo[300];
        } LoadData;

    //*****USED TO RETURN ARRAY OF LOADDATA STRUCT FROM FUNCTION******\\
    typedef struct{
        LoadData data[300];
    } DataArray;

    DataArray loadData();
    unsigned int utf8_to_codepoint(const unsigned char *u, int *lenptr);

    int main(int argc, char **argv)
    {
        FILE *fp = fopen("sample.txt", "r"); //param1 = argv[1]
        unsigned char sampleText[3000];
        DataArray unicodeDataArray = loadData();
        LoadData unicodeData[300];
        int lenptr = 0;
        //unicodeDataArray = loadData();
        memcpy(unicodeData, unicodeDataArray.data, sizeof(unicodeDataArray.data));

        printf("LangCount: %d\n", unicodeData[0].languagecount);

        //***************THIS IS THE LOOP I AM HAVING ISSUES WITH*************\\
        for(int i = 0; fgets((char *) sampleText, 3000, fp) != NULL; i++)
        {
            int temp;
            temp = utf8_to_codepoint(&sampleText[i], &lenptr);

            printf("i: %d\n", i);
            printf("%d\n", temp);

            for(int k = 0; k < unicodeData[0].languagecount; k++)
            {
                if(temp <= unicodeData[k].max && temp >= unicodeData[k].min)
                {
                    unicodeData[k].numChars++;
                }
            }
        }
        puts("Here?");

        //********************NOT CONCERNED ABOUT THE FOLLOWING SEGMENT************\\       

        int max = 0;
        int maxindex;
        for(int i = 0; i < (*unicodeData).languagecount; i++)
        {
            if(unicodeData[i].max > max)
            {
                max = unicodeData[i].max;
                maxindex = i;
            }
        }

        puts(unicodeData[maxindex].lang);

        //puts(sampleText);
        getchar();
    }

    //***************LOADDATA() HAS BEEN TESTED TO RETURN THE PROPER STRUCTURE***********\\

    DataArray loadData()
    {
        setbuf(stdout, NULL);
        DataArray dataArray;
        LoadData data[300];
        char hexstring[300];
        int languagecount = 0;

        FILE *blocks;
        blocks = fopen("Blocks.txt", "r");
        if(blocks == NULL)
        {
            perror("Blocks.txt not found");
            memcpy(dataArray.data, data, sizeof(data));
            return(dataArray);
        }

        //Store the hex value ranges and their affiliated
        //languages into data.allinfo.
        while(fgets(hexstring,100,blocks) != NULL)
        {
            if(hexstring[0] != '\n' && hexstring[0] != '#')
                    {
                        strcpy(data[languagecount].lineinfo, hexstring);
                        languagecount++;
                    }
        }

        for(int i = 0; i < languagecount; i++)
        {
        data[i].languagecount = languagecount;
        }

        fclose(blocks);

        for(int i = 0; i < languagecount; i++)
        {
            char temp1[300];
            memset(temp1, 0, sizeof temp1);
            strcpy(temp1, data[i].lineinfo);

            for(int k = 0; k < strlen(temp1); k++)
            {
                char temp2[300];
                memset(temp2, 0, sizeof temp2); //This line of code is a lifesaver! <3 memset
                if(temp1[k] == ';')
                {
                    k = k + 2;
                    for(int j = 0; k < strlen(temp1); j++)
                    {
                        temp2[j] = temp1[k];
                        k++;
                    }
                    strcpy(data[i].lang, temp2);
                    //break;
                }
            }
        }

        for(int i = 0; i < languagecount; i++)
        {
            char tempmin[10];
            for(int k = 0; (data[i].lineinfo[k] != '.'); k++)
            {
                tempmin[k] = data[i].lineinfo[k];
            }
            //puts(tempmin);
            data[i].min = (int)strtol(tempmin, NULL, 16);
        }

        for(int i = 0; i < languagecount; i++)
        {
            int dotindex = 0;
            char tempmax[10];
            while(data[i].lineinfo[dotindex] != '.')
            {
                dotindex++;
            }

            int maxindex = dotindex + 2;
            for(int k = 0; data[i].lineinfo[maxindex+k] != ';'; k++)
            {
                tempmax[k] = data[i].lineinfo[maxindex+k];
            }
            data[i].max = (int)strtol(tempmax, NULL, 16);
        }

        memcpy(dataArray.data, data, sizeof(data));
        return dataArray;
    }

    //*******THIS CODE HAS BEEN SUPPLIED TO ME AND SHOULD NOT NEED MODIFYING********\\    

    extern int isutf8(const unsigned char *u) {
       // Validate utf8 character.
       // Returns the length, 0 if invalid.
       int len = 0;

       if (u) {
          if (*u < 0xc0) {
             len = 1;
          } else {
             if ((*u & 0xe0) == 0xc0) {
                // U-00000080 - U-000007FF : 110xxxxx 10xxxxxx
                len = 2;
             } else if ((*u & 0xf0) == 0xe0) {
                // U-00000800 - U-0000FFFF : 1110xxxx 10xxxxxx 10xxxxxx
                len = 3;
             } else if ((*u & 0xf8) == 0xf0) {
                // U-00010000 - U-001FFFFF : 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                len = 4;
             } else {
                // malformed UTF-8 character
                return 0;
             }
             // Check that the UTF-8 character is OK
             int i;
             for (i = 1; i < len; i++ ) {
                if ((u[i] & 0xC0) != 0x80) {
                   return 0;
                }
             }
          }
       }
       return len;
    }

    extern unsigned int utf8_to_codepoint(const unsigned char *u,
                                          int               *lenptr) {
       // Returns 0 if something goes wrong
       // Passes back the length
       unsigned int cp = 0;

       *lenptr = 0;
       if (u) {
          if (*u < 0xc0) {
             cp = (unsigned int)*u;
             *lenptr = 1;
          } else {
             *lenptr = isutf8(u);
             if (*lenptr == 0) {
                return 0;
             }
             switch (*lenptr) {
                case 2:
                     cp = (u[0] - 192) * 64 + u[1] - 128;
                     break;
                case 3:
                     cp = (u[0] - 224) * 4096
                        + (u[1] - 128) * 64 + u[2] - 128;
                     break;
                default:
                     cp = (u[0] - 240) * 262144
                         + (u[1] - 128) * 4096
                         + (u[2] - 128) * 64 + u[3] - 128;
                     break;
             }
          }
       }
       return cp;
    }

    //
    //  Returns the length of s in CHARACTERS, not bytes
    //

Sample.txt (This is in Armenian..I think.)

Նապոլեոն I Բոնապարտ (կորսիկերեն՝ Napulione Buonaparte, իտալերեն՝ Napoleone Buonaparte, ֆրանսերեն՝ Napoléon Bonaparte, օգոստոսի 15, 1769[1] , Այաչչո[2] - մայիսի 5, 1821[1] , Լոնգվուդ Հաուս) ֆրանսիացիների առաջին կայսր 1804 թ մայիսի 18-1814 թ ապրիլ 6 և 1815 թ մարտի 20- 1815 թ հունիսի 22։ Շառլ Բոնապարտի և Լետիտիա Ռոմոլինոյի երկրորդ երեխան։ Որպես ռազմական գործիչ Նապոլեոն Բոնապարտը սկսեց կարիերան Տուլոնի պաշարումով՝ 1793 թ սեպտեմբերի 18- դեկտեմբերի 18։ 24 տարեկանում նշանակվեց Ֆրանսիայի առաջին հանրապետության զորքերի գեներալ, ինչպես նաև Իտալիայի զորքերի հրամանատար։ Նա եկավ իշխանության 1799 թ-ի հանրահայտ 18 Բռումիերից հետո (նոյեմբերի 9)։ 1802 թ օգոստոսի 2-ին նշանակվեց Ֆրանսիայի Առաջին կոնսուլ, 1804 թ մայիսի 18-ին՝ ցմահ կոնսուլ։ Եվ վերջապես 1804 թ դեկտեմբերի 2-ին Փարիզի Աստվածամոր տաճարում Հռոմի պապի կողմից օծվեց կայսր։

Որպես զորքերի հրամանատար փորձել է լուծարել Մեծ Բրիտանիայի կողմից ստեղծված և ֆինանսավորված դաշնակիցների կոալիցիաները։ Դրա համար նա բանակը առաջնորդել է Նեղոսից և Ավստրիայից մինչև Պրուսիա և Լեհաստան։ Նրա բազմաթիվ փայլուն հաղթանակները (Արկոլ, Մարենգո, Աուստեռլից, Ֆրիդլանդ և այլն) ապահովեցին Ֆրանսիայի գերիշխանությունը մայրցամաքային Եվրոպայում։

Որպես պետության ղեկավար կատարել է մի շարք բարեփոխումներ՝ վարչական, իրավունքի, տրանսպորտի, տնտեսության, գիտության և այլ ոլորտներում։ Նրա օրոք Ֆրանսիան հասավ իր տարածքային մեծության գագաթնակետին՝ ունենալով 134 դեպարտամենտ 1812 թ.-ի դրությամբ։ Հայտնի է Նապոլեոնի քաղաքացիական օրենսգիրքը, որը Ֆրանսիայում օգտագործվում է մինչ այսօր։ Ստեղծել է Ֆրանսիայի բանկը՝ 1800 թ-ին, որը գործում է մինչ այսօր։

Բացի ֆրանսիացիների կայսր լինելուց, նա նաև ստանձնել է Իտալիայի նախագաhի պաշտոնը՝ 1802-1805 թթ, ապա Իտալիայի արքայի՝ 1805-1814, ինչպես նաև հանդիսանում էր Ռեյնի կոնֆեդերացիայի պրոտեկտոր (պաշտպան): Նա նաև ստեղծեց Վարշավայի դքսությունը՝ տալով նրանց ներքին ինքնավարություն։

Մեծ Բրիտանիայի դեմ Նապոլենը կիրառում էր մայրցամաքային բլոկադայի քաղաքականությունը, որին միացան Նապոլեոնի դաշնակից պետությունները։ Ըստ որոշ պատմաբանների՝ Մայրցամաքային բլոկադան դարձավ Նապոլեոնի ձեռնարկած արշավանքների հիմնական պատճառը, նախ Իսպանիա, ապա Պորտուգալիա: 1807 թ Ֆրիդլանդում տեղի ունեցած ճակատամարտում Նապոլեոնը ջախջախեց Ռուսաստանին և ստիպեց նրանց կնքել պայմանագիր (Տիլզիտի պայմանագիր) և միանալ մայրցամաքային բլոկադային։ Երկար բանակցություններից հետո, հասկանալով, որ Ռուսաստանի կայսրությունը չի պատրաստվում հետևել Տիլզիտի պայմանագրի կետերին, 1812 թ-ին կազմակերպում է արշավանք դեպի Ռուսաստան, հասնում մինչև Մոսկվա, հաղթում Բորոդինոյի ճակաամարտում և մտնում Մոսկվա։ Սակայն չունենալով բավարար սնունդ և զենք՝ Բոնապարտը ստիպված նահանջում է՝ արդյունքում կրելով լուրջ վնասներ։

Չկորցնելով պահը՝ Մեծ Բրիտանիան ստեղծում է հերթական կոալիցիան: Ֆրանսիան լուրջ պարտություն է կրում Իսպանիայում (Վիտորիայի ճակատամարտ) և Գերմանիայում (Լայպցիգի ճակատամարտ): Լայպցիգի ճակատամարտից հետո դաշնակիցներն առանց դիմադրության մտնում են Փարիզ: Կնքվում է պայմանագիր՝ ըստ որի Ֆրանսիան վերադառնում է 1789 թվականի տարածքին, վերականգնվում է Բուրբոնների դինաստիան։ Իսկ Նապոլեոնին տրվեց Էլբա կղզին, որը պետք է հսկվեր անգլիական նավատորմի կողմից։ Էլբայում նա կատարեց մի շարք բարեփոխումներ, հատկապես ստեղծեց ճանապարհների զարգացած համակարգ, որի մի մասը պահպանված է մինչ օրս։

Հասկանալով, որ ֆրանսիացիները դեմ են Բուրբոններին, նա կարողանում է փախչել Էլբայից, ստեղծել նոր բանակ և վերականգնել կայսրությունը։ Նրա կառավարման այս շրջանը հայտնի է հարյուր օր (cent-jours) անունով։ Տանելով մի քանի հաղթանակ՝ 1815 թ հունիսի 18-ն նա որոշիչ ճակատամարտ է տալիս Բելգիայի Վաթեռլո բնակավայրի մոտ և կրում պարտություն։ Չնայած նրան, որ Նապոլեոնն ուներ հնարավորություն փախչել ԱՄՆ, սակայն նա հանձնվում է Մեծ Բրիտանիային, որն էլ նրան ուղարկում է Հարավային Աֆրիկայի մոտ գտնվող Սուրբ Հեղինե կղզի, որտեղ էլ 1821 թ մայիսի 5-ին վախճանվում է։

Նրա կյանքը և գործունեությունը դարձել են 18-րդ դարի իսկական լեգենդ։ Նապոլեոնին իրենց ստեղծագործություններում անդրադարձել են Բալզակը, Դյուման, Ստենդալը, Լերմոնտովը, Դոստոեվսկին , Տոլստոյը և այլն։ Նրա մասին ամենահայտնի գիրքը Էմանուել դը Լաս-Կասի Սբ Հեղինեի հուշերն է (Mémorial de Sainte-Hélène ), որը հեղինակը գրել է Նապոլեոնի թելադրանքով՝ ավելացնելով իր հիշողությունները։

Output:

i: 0
1350
i: 1
0
i: 2
1408
i: 3
128
i: 4
1402
i: 5
186
i: 6
1387
i: 7
171
i: 8
178
i: 9
1408
i: 10
1398
i: 11
182
i: 12
1377
i: 13
161
i: 14
182
i: 15
1412
i: 16
132
Here?
Supplementary Private Use Area-B

Blocks.txt:

# Blocks-8.0.0.txt
# Date: 2014-11-10, 23:04:00 GMT [KW]
#
# Unicode Character Database
# Copyright (c) 1991-2014 Unicode, Inc.
# For terms of use, see http://www.unicode.org/terms_of_use.html
# For documentation, see http://www.unicode.org/reports/tr44/
#
# Format:
# Start Code..End Code; Block Name

# ================================================

# Note:   When comparing block names, casing, whitespace, hyphens,
#         and underbars are ignored.
#         For example, "Latin Extended-A" and "latin extended a" are equivalent.
#         For more information on the comparison of property values, 
#            see UAX #44: http://www.unicode.org/reports/tr44/
#
#  All block ranges start with a value where (cp MOD 16) = 0,
#  and end with a value where (cp MOD 16) = 15. In other words,
#  the last hexadecimal digit of the start of range is ...0 
#  and the last hexadecimal digit of the end of range is ...F.
#  This constraint on block ranges guarantees that allocations
#  are done in terms of whole columns, and that code chart display
#  never involves splitting columns in the charts.
#
#  All code points not explicitly listed for Block
#  have the value No_Block.

# Property: Block
#
# @missing: 0000..10FFFF; No_Block

0000..007F; Basic Latin
0080..00FF; Latin-1 Supplement
0100..017F; Latin Extended-A
0180..024F; Latin Extended-B
0250..02AF; IPA Extensions
02B0..02FF; Spacing Modifier Letters
0300..036F; Combining Diacritical Marks
0370..03FF; Greek and Coptic
0400..04FF; Cyrillic
0500..052F; Cyrillic Supplement
0530..058F; Armenian
0590..05FF; Hebrew
0600..06FF; Arabic
0700..074F; Syriac
0750..077F; Arabic Supplement
0780..07BF; Thaana
07C0..07FF; NKo
0800..083F; Samaritan
0840..085F; Mandaic
08A0..08FF; Arabic Extended-A
0900..097F; Devanagari
0980..09FF; Bengali
0A00..0A7F; Gurmukhi
0A80..0AFF; Gujarati
0B00..0B7F; Oriya
0B80..0BFF; Tamil
0C00..0C7F; Telugu
0C80..0CFF; Kannada
0D00..0D7F; Malayalam
0D80..0DFF; Sinhala
0E00..0E7F; Thai
0E80..0EFF; Lao
0F00..0FFF; Tibetan
1000..109F; Myanmar
10A0..10FF; Georgian
1100..11FF; Hangul Jamo
1200..137F; Ethiopic
1380..139F; Ethiopic Supplement
13A0..13FF; Cherokee
1400..167F; Unified Canadian Aboriginal Syllabics
1680..169F; Ogham
16A0..16FF; Runic
1700..171F; Tagalog
1720..173F; Hanunoo
1740..175F; Buhid
1760..177F; Tagbanwa
1780..17FF; Khmer
1800..18AF; Mongolian
18B0..18FF; Unified Canadian Aboriginal Syllabics Extended
1900..194F; Limbu
1950..197F; Tai Le
1980..19DF; New Tai Lue
19E0..19FF; Khmer Symbols
1A00..1A1F; Buginese
1A20..1AAF; Tai Tham
1AB0..1AFF; Combining Diacritical Marks Extended
1B00..1B7F; Balinese
1B80..1BBF; Sundanese
1BC0..1BFF; Batak
1C00..1C4F; Lepcha
1C50..1C7F; Ol Chiki
1CC0..1CCF; Sundanese Supplement
1CD0..1CFF; Vedic Extensions
1D00..1D7F; Phonetic Extensions
1D80..1DBF; Phonetic Extensions Supplement
1DC0..1DFF; Combining Diacritical Marks Supplement
1E00..1EFF; Latin Extended Additional
1F00..1FFF; Greek Extended
2000..206F; General Punctuation
2070..209F; Superscripts and Subscripts
20A0..20CF; Currency Symbols
20D0..20FF; Combining Diacritical Marks for Symbols
2100..214F; Letterlike Symbols
2150..218F; Number Forms
2190..21FF; Arrows
2200..22FF; Mathematical Operators
2300..23FF; Miscellaneous Technical
2400..243F; Control Pictures
2440..245F; Optical Character Recognition
2460..24FF; Enclosed Alphanumerics
2500..257F; Box Drawing
2580..259F; Block Elements
25A0..25FF; Geometric Shapes
2600..26FF; Miscellaneous Symbols
2700..27BF; Dingbats
27C0..27EF; Miscellaneous Mathematical Symbols-A
27F0..27FF; Supplemental Arrows-A
2800..28FF; Braille Patterns
2900..297F; Supplemental Arrows-B
2980..29FF; Miscellaneous Mathematical Symbols-B
2A00..2AFF; Supplemental Mathematical Operators
2B00..2BFF; Miscellaneous Symbols and Arrows
2C00..2C5F; Glagolitic
2C60..2C7F; Latin Extended-C
2C80..2CFF; Coptic
2D00..2D2F; Georgian Supplement
2D30..2D7F; Tifinagh
2D80..2DDF; Ethiopic Extended
2DE0..2DFF; Cyrillic Extended-A
2E00..2E7F; Supplemental Punctuation
2E80..2EFF; CJK Radicals Supplement
2F00..2FDF; Kangxi Radicals
2FF0..2FFF; Ideographic Description Characters
3000..303F; CJK Symbols and Punctuation
3040..309F; Hiragana
30A0..30FF; Katakana
3100..312F; Bopomofo
3130..318F; Hangul Compatibility Jamo
3190..319F; Kanbun
31A0..31BF; Bopomofo Extended
31C0..31EF; CJK Strokes
31F0..31FF; Katakana Phonetic Extensions
3200..32FF; Enclosed CJK Letters and Months
3300..33FF; CJK Compatibility
3400..4DBF; CJK Unified Ideographs Extension A
4DC0..4DFF; Yijing Hexagram Symbols
4E00..9FFF; CJK Unified Ideographs
A000..A48F; Yi Syllables
A490..A4CF; Yi Radicals
A4D0..A4FF; Lisu
A500..A63F; Vai
A640..A69F; Cyrillic Extended-B
A6A0..A6FF; Bamum
A700..A71F; Modifier Tone Letters
A720..A7FF; Latin Extended-D
A800..A82F; Syloti Nagri
A830..A83F; Common Indic Number Forms
A840..A87F; Phags-pa
A880..A8DF; Saurashtra
A8E0..A8FF; Devanagari Extended
A900..A92F; Kayah Li
A930..A95F; Rejang
A960..A97F; Hangul Jamo Extended-A
A980..A9DF; Javanese
A9E0..A9FF; Myanmar Extended-B
AA00..AA5F; Cham
AA60..AA7F; Myanmar Extended-A
AA80..AADF; Tai Viet
AAE0..AAFF; Meetei Mayek Extensions
AB00..AB2F; Ethiopic Extended-A
AB30..AB6F; Latin Extended-E
AB70..ABBF; Cherokee Supplement
ABC0..ABFF; Meetei Mayek
AC00..D7AF; Hangul Syllables
D7B0..D7FF; Hangul Jamo Extended-B
D800..DB7F; High Surrogates
DB80..DBFF; High Private Use Surrogates
DC00..DFFF; Low Surrogates
E000..F8FF; Private Use Area
F900..FAFF; CJK Compatibility Ideographs
FB00..FB4F; Alphabetic Presentation Forms
FB50..FDFF; Arabic Presentation Forms-A
FE00..FE0F; Variation Selectors
FE10..FE1F; Vertical Forms
FE20..FE2F; Combining Half Marks
FE30..FE4F; CJK Compatibility Forms
FE50..FE6F; Small Form Variants
FE70..FEFF; Arabic Presentation Forms-B
FF00..FFEF; Halfwidth and Fullwidth Forms
FFF0..FFFF; Specials
10000..1007F; Linear B Syllabary
10080..100FF; Linear B Ideograms
10100..1013F; Aegean Numbers
10140..1018F; Ancient Greek Numbers
10190..101CF; Ancient Symbols
101D0..101FF; Phaistos Disc
10280..1029F; Lycian
102A0..102DF; Carian
102E0..102FF; Coptic Epact Numbers
10300..1032F; Old Italic
10330..1034F; Gothic
10350..1037F; Old Permic
10380..1039F; Ugaritic
103A0..103DF; Old Persian
10400..1044F; Deseret
10450..1047F; Shavian
10480..104AF; Osmanya
10500..1052F; Elbasan
10530..1056F; Caucasian Albanian
10600..1077F; Linear A
10800..1083F; Cypriot Syllabary
10840..1085F; Imperial Aramaic
10860..1087F; Palmyrene
10880..108AF; Nabataean
108E0..108FF; Hatran
10900..1091F; Phoenician
10920..1093F; Lydian
10980..1099F; Meroitic Hieroglyphs
109A0..109FF; Meroitic Cursive
10A00..10A5F; Kharoshthi
10A60..10A7F; Old South Arabian
10A80..10A9F; Old North Arabian
10AC0..10AFF; Manichaean
10B00..10B3F; Avestan
10B40..10B5F; Inscriptional Parthian
10B60..10B7F; Inscriptional Pahlavi
10B80..10BAF; Psalter Pahlavi
10C00..10C4F; Old Turkic
10C80..10CFF; Old Hungarian
10E60..10E7F; Rumi Numeral Symbols
11000..1107F; Brahmi
11080..110CF; Kaithi
110D0..110FF; Sora Sompeng
11100..1114F; Chakma
11150..1117F; Mahajani
11180..111DF; Sharada
111E0..111FF; Sinhala Archaic Numbers
11200..1124F; Khojki
11280..112AF; Multani
112B0..112FF; Khudawadi
11300..1137F; Grantha
11480..114DF; Tirhuta
11580..115FF; Siddham
11600..1165F; Modi
11680..116CF; Takri
11700..1173F; Ahom
118A0..118FF; Warang Citi
11AC0..11AFF; Pau Cin Hau
12000..123FF; Cuneiform
12400..1247F; Cuneiform Numbers and Punctuation
12480..1254F; Early Dynastic Cuneiform
13000..1342F; Egyptian Hieroglyphs
14400..1467F; Anatolian Hieroglyphs
16800..16A3F; Bamum Supplement
16A40..16A6F; Mro
16AD0..16AFF; Bassa Vah
16B00..16B8F; Pahawh Hmong
16F00..16F9F; Miao
1B000..1B0FF; Kana Supplement
1BC00..1BC9F; Duployan
1BCA0..1BCAF; Shorthand Format Controls
1D000..1D0FF; Byzantine Musical Symbols
1D100..1D1FF; Musical Symbols
1D200..1D24F; Ancient Greek Musical Notation
1D300..1D35F; Tai Xuan Jing Symbols
1D360..1D37F; Counting Rod Numerals
1D400..1D7FF; Mathematical Alphanumeric Symbols
1D800..1DAAF; Sutton SignWriting
1E800..1E8DF; Mende Kikakui
1EE00..1EEFF; Arabic Mathematical Alphabetic Symbols
1F000..1F02F; Mahjong Tiles
1F030..1F09F; Domino Tiles
1F0A0..1F0FF; Playing Cards
1F100..1F1FF; Enclosed Alphanumeric Supplement
1F200..1F2FF; Enclosed Ideographic Supplement
1F300..1F5FF; Miscellaneous Symbols and Pictographs
1F600..1F64F; Emoticons
1F650..1F67F; Ornamental Dingbats
1F680..1F6FF; Transport and Map Symbols
1F700..1F77F; Alchemical Symbols
1F780..1F7FF; Geometric Shapes Extended
1F800..1F8FF; Supplemental Arrows-C
1F900..1F9FF; Supplemental Symbols and Pictographs
20000..2A6DF; CJK Unified Ideographs Extension B
2A700..2B73F; CJK Unified Ideographs Extension C
2B740..2B81F; CJK Unified Ideographs Extension D
2B820..2CEAF; CJK Unified Ideographs Extension E
2F800..2FA1F; CJK Compatibility Ideographs Supplement
E0000..E007F; Tags
E0100..E01EF; Variation Selectors Supplement
F0000..FFFFF; Supplementary Private Use Area-A
100000..10FFFF; Supplementary Private Use Area-B

# EOF

Your loop reads up to 3000 characters in each iteration due to fgets((char *) sampleText, 3000, fp) , but then displays only one of them.

You need an inner loop that iterates over the characters you read into the sampleText buffer:

while (fgets((char *) sampleText, 3000, fp) != NULL)
{
    for (int i=0; sampleText[i]; i++) {
        //handle sampleText[i]
    }
}

Correct me if I'm wrong but that looks very strange to me:

   for(int i = 0; fgets((char *) sampleText, 3000, fp) != NULL; i++)
   {
        int temp;
        temp = utf8_to_codepoint(&sampleText[i], &lenptr);
        ....
   }

Thus, with the first line you call utf8_to_codepoint( <line>, &lenptr); with the second line it's <line>+1 (skipping the first char) and so on.. I think that's what you intend to do

I'll admit that I haven't read through all your code, but I believe your issue is that you are overwriting sampleText on each loop iteration, when you want to loop through each character in sampleText . I think your loop is supposed to look like this:

while (fgets((char *) sampleText, 3000, fp) != NULL)
{
    for(int i = 0; sampleText[i]; i++)
    {
        int temp;
        temp = utf8_to_codepoint(&sampleText[i], &lenptr);
        printf("%d\n", temp);
        printf("i: %d\n", i);
        for(int k = 0; k < unicodeData[0].languagecount; k++)
        {
            if(temp <= unicodeData[k].max && temp >= unicodeData[k].min)
            {
                unicodeData[k].numChars++;
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM