blueboyz's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
26 (0.07 per day)
Joined:
24-April 12
Profile Views:
574
Last Active:
User is offline Jun 07 2012 10:50 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   blueboyz has not set their status

Posts I've Made

  1. In Topic: Writing different node to different files

    Posted 27 May 2012

    I am already trying to do it like this
    void writeFileToNode(char *klas,int lng)
    {
        char *file_any;
        FILE *infile=fopen(klas,"r");
        if (infile==NULL)
        {
            printf("File %s tidak ditemukan",klas);
            getch();
        }
        else
        {
            fgets(file_any,99,infile);
            klas[(strlen(klas)-4)] = '\0';
            insertKelas(klas,lng);
            while(strtok(file_any,",")!=NULL)
            {
                printf("%s",file_any);
            }
    
    


    But why it can't input to my program?
  2. In Topic: Writing different node to different files

    Posted 23 May 2012

    Hello... Now I touching this project again. How I can read all files to just one variables in fgets and how I limit my string length in fgets? It will read whole character in file right?

    And anyway, I remember someone told me to not using fflush(stdin) because it will makes undefined behaviour. But how I can remove buffer from my input if not using this? Because in my program if I try to stop my buffer with getchar() it works for sometimes like if I just input my data once. If I input it twice getchar() won't work and it will vanishing my 1st char.

    I hope somebody still remember this thread :D
  3. In Topic: Writing different node to different files

    Posted 7 May 2012

    Ok, now I can fixed my input. Thanks a lot.
    Anyway I still can't read from file to my program. This is my file look alike.
    albi,1150,2011,3.28
    arik,1050,2010,2.50
    
    


    And this is my code :
    void writeFileToNode(char *klas)
    {
        char nama[31],nim[16];
        int angkatan;
        float ipk;
        FILE *infile=fopen(klas,"r");
        if (infile==NULL)
        {
            printf("File %s tidak ditemukan",klas);
            getch();
        }
        else
        {
            klas[(strlen(klas)-4)] = '\0';
            insertKelas(klas);
            kelas *itr=head;
            //this is my looping
            for(int i=0;i<40;i++)
                //this is how I input it to my program
                fscanf(infile,"%30s,%15s,%d,%f\n",itr->siswa[i].nama,itr->siswa[i].nim,&itr->siswa[i].angkatan,&itr->siswa[i].ipk);
            fclose(infile);
            printf("Anda telah berhasil mengimport\n");
            getch();
        }
    }
    


    Can anybody help me? :D
  4. In Topic: Writing different node to different files

    Posted 2 May 2012

    View Postturboscrew, on 02 May 2012 - 11:22 AM, said:

    How about fgets (like jimplumberg suggested) and then finding the newline in the string and replacing it with NUL-character ('\0').

    Ok, I will try it.

    View Postaaa111, on 02 May 2012 - 11:24 AM, said:

    One solution is the following:
    while(getchar()!='\n')
    	continue;
    
    

    Using getchar()? Doesn't getchar just saving a character? How it can be used to save string?
  5. In Topic: Writing different node to different files

    Posted 2 May 2012

    So what should I do to discard \n from my input? Am I need to make own function? Isn't that slowing my program?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

blueboyz hasn't added any friends yet.

Comments

blueboyz has no profile comments yet. Why not say hello?