User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 425,824 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,980 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 213 | Replies: 0 | Solved
Reply
Join Date: Jan 2008
Posts: 8
Reputation: mm-marek is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mm-marek mm-marek is offline Offline
Newbie Poster

data from file...

  #1  
Jun 3rd, 2008
Hi,

I need to transfer data from file to fields... Can anyone help me?

file:
name surname weight age male/female
name surname weight age male/female
marek mixa 70 23 M
...


kód:
typedef struct lidi
{
	char cl_jmeno[16], cl_prijmeni[21], cl_muz_zena[1],cl_vyska[3], cl_vaha[3];
} LIDI;
LIDI lidi[6];
i know that i have it only by char, but if i will do it in integer, im also not able to do it
int nacti_lidi()
{ 
	int i, j,lokace,cislo,;
	char c;

   printf("obsah souboru:\n");
	 for(i=0; i<2;i++) //dva radky
	 {
      lokace = 1; 
      cislo = -1;         
      for(j=0; j<60; j++) //omezeni radku
      {
       c = getc(zdrojovysoubor);
       if(c == '\n'){
        printf("\n"); //vypisem obsah souboru
        break;
       }else{
             if(c == ' '){
                  lokace ++; //udava co plnime za pole
                  printf(" ");  
                  cislo = -1; //udava cislo v poli od nuly
                  continue;
             }  
             cislo ++;
                
              printf("%c", c ); //vypisem obsah souboru
              if(lokace == 1){
               lidi[i].cl_jmeno[cislo] = c;
              } 
              else if(lokace == 2){
               lidi[i].cl_prijmeni[cislo] = c;
              }
              else if(lokace == 3){
               lidi[i].cl_vyska[cislo] = c;
              }
              else if(lokace == 4){
               lidi[i].cl_vaha[cislo] = c;
              }
              else if(lokace == 5){
               lidi[i].cl_muz_zena[cislo] = c;
              }
       }      

      }
	}
 printf("\n***********************************\n");	

}

I think that right way is atoi() but Im not able to finish that... Can anyone help me? Thanks
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 4:22 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC