strcmp not working with the same string with file in c

So I have a problem that strcmp not working even the string is same. The cmp between destination and source string is have same string, but when strcmp it, it not working. See the code for explanation:

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

int main()
{
    FILE *fp;
    fp = fopen("test.txt", "r");
    char namalengkap[100], gender[100], charnamafile[50], tempat[50], temp[1000], tdeeprint[100], gendercheck;
    int umur, tb, bb, x;
    int cmp1, cmp2, cmp3, cmp4, cmp5, cmp6, check;
    float tdeenum;
    fscanf(fp, "Username : %s\nPassword : %s", tempat, temp);
    fscanf(fp, "\n\n\n=============================DATA PRIBADI USER===============================\n");
    fscanf(fp, "= Nama Lengkap       : %52[^\n] =\n", namalengkap);
    fscanf(fp, "= Jenis Kelamin      : %52[^\n] =\n", gender);
    fscanf(fp, "= Umur               : %52d =\n", &umur);
    fscanf(fp, "= Tinggi Badan (CM)  : %52d =\n", &tb);
    fscanf(fp, "= Berat  Badan (KG)  : %52d =\n", &bb);
    fscanf(fp, "= Rutinitas Olahraga : %52[^\n] =\n", tdeeprint);       
 
    fscanf(fp, "=============================================================================\n");
    cmp1 = strcmp(tdeeprint, "Jarang Berolahraga");
    cmp2 = strcmp(tdeeprint, "1 Hingga 3 Hari Dalam Seminggu");
    cmp3 = strcmp(tdeeprint, "3 Hingga 5 Hari Dalam Seminggu");
    cmp4 = strcmp(tdeeprint, "6 Hingga 7 Hari Dalam Seminggu");
    cmp5 = strcmp(tdeeprint, "Pekerjaan Fisik Berat Atau Olahraga 2x Dalam Sehari");
    if (cmp1 == 0) {
        tdeenum = 1.2;
        printf("tde1work : %f\n", tdeenum);
    } else
    if (cmp2 == 0) {
        tdeenum = 1.375;
        printf("tde2work : %f\n", tdeenum);
    } else
     if (cmp3 == 0) {
        tdeenum = 1.55;
        printf("tde3work : %f\n", tdeenum);
    } else
    if (cmp4 == 0) {
        tdeenum = 1.725;
        printf("tde4work : %f\n", tdeenum);
    } else
    if (cmp5 == 0) {
        tdeenum = 1.9;
        printf("tde5work : %f\n", tdeenum);
    }
    printf("\nUsername : %s\n", tempat);
    printf("\nPassword : %s\n", temp);
    printf("\nName : %s\n", namalengkap);
    printf("\nGender : %s\n", gender);
    printf("\nUmur : %d\n", umur);
    printf("\nTB : %d\n", tb);
    printf("\nBB : %d\n", bb);
    printf("\ntdeeprint : %s\n", tdeeprint);
    printf("\ntdeepnum : %f\n", tdeenum);
    fclose(fp);
    return 0;
}

When I run it:


Username : hitunga

Password : 12345

Name : a

Gender : Perempuan

Umur : 30

TB : 155

BB : 50

tdeeprint : Jarang Berolahraga

tdeepnum : 0.000000

Process returned 0 (0x0)   execution time : 0.043 s
Press any key to continue.

The test.txt file content:

Username : hitunga
Password : 12345

=============================DATA PRIBADI USER===============================
= Nama Lengkap       : a                                                    =
= Jenis Kelamin      : Perempuan                                            =
= Umur               : 30                                                   =
= Tinggi Badan (CM)  : 155                                                  =
= Berat  Badan (KG)  : 50                                                   =
= Rutinitas Olahraga : Jarang Berolahraga                                   =
= TDEE               : 1.200                                                = 
=============================================================================

So what wrong on my code? I really confused why isn't working. It is literally same string comparison but not working. Thank you

Edit: So I replace the cmp section with fscanf, but still not getting the number

fscanf(fp, "= TDEE               : %52.3f =\n", &datusr.tdeenum);


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation