Hi,
I would like to know how to do something like that:
ThanksCode:scanf ("%d",iNoEmploye); &TabEmploye[iNoEmploye].iNo = iNoEmploye;
Hi,
I would like to know how to do something like that:
ThanksCode:scanf ("%d",iNoEmploye); &TabEmploye[iNoEmploye].iNo = iNoEmploye;
Thanks, now I want to print a structure in a file without overwriting it (because it's information about different person and I want them all in the file.)
ThanksCode:typedef struct { int iNo; char sNas[9]; char sPrenom[30]; char sNom[30]; char cSexe; char sFin[3]; }EMPLOYE; EMPLOYE TabEmploye[99];
OK, open a text file for writing and let fprintf() write out the information line by line.
This is what i'm trying to do but unfortunatly, with a structure, I am not able to do something right. I would help me if I could have an example please.
What have you tried?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
this
Code:void AjouterEmploye(void) /*----------------------------------------------------------------------------*/ { clrscr(); gotoxy(20,23); int iNoEmploye; typedef struct { int iNo; char sNas[9]; char sPrenom[30]; char sNom[30]; char cSexe; char sAdresse[30]; char sVille[30]; char cEtatCivil; int iJourNais; int iMoisNais; int iAnNais; char sProv[30]; char sCodPost[6]; float fTauxHre; float fExempFed; float fExempPro; char sCode[3]; char sPrem[3]; char sFin[3]; }EMPLOYE; { FILE * pFichier; //pour la lecture du fichier, int i; int iValide; EMPLOYE TabEmploye[99]; clrscr(); time_t rawtime; time ( &rawtime ); gotoxy(57,1); printf ( "%s", ctime (&rawtime) ); gotoxy(1,1); puts ("(2.2)"); gotoxy(23,1); puts (" Le Roi de L'informatique Inc. "); gotoxy(32,2); puts ("Systeme de paye"); gotoxy(31,3); puts ("Ajouter un employe"); gotoxy(6,5); puts ("Numero de l'employe:"); gotoxy(47,7); puts ("NAS:"); gotoxy(2,9); puts ("Nom:"); gotoxy(21,9); puts ("Prenom:"); gotoxy(47,9); puts ("Sexe(F/M):"); gotoxy(59,9); puts ("Etat civil(I/F):"); gotoxy(67,10); puts ("AAAA MM JJ"); gotoxy(2,11); puts ("Adresse:"); gotoxy(47,11); puts ("Date de naissance:"); gotoxy(2,13); puts ("Ville:"); gotoxy(24,13); puts ("Prov.:"); gotoxy(47,13); puts ("Taux horaire:"); gotoxy(2,15); puts ("Code postal:"); gotoxy(24,15); puts ("Telephone:( ) -"); gotoxy(2,17); puts ("Exemption federal:"); gotoxy(47,17); puts ("Taux horraire:"); fflush(stdin); gotoxy(26,5); scanf ("%d",&iNoEmploye); i=iNoEmploye; TabEmploye[i].iNo = iNoEmploye; gotoxy(51,7); scanf("%d",TabEmploye[i].sNas); gotoxy(6,9); scanf("%s",TabEmploye[i].sNom); gotoxy(28,9); scanf("%s",TabEmploye[i].sPrenom); gotoxy(57,9); scanf("%s",&TabEmploye[i].cSexe); gotoxy(75,9); scanf("%s",&TabEmploye[i].cEtatCivil); fflush(stdin); gotoxy(10,11); gets (TabEmploye[i].sAdresse); gotoxy(67,11); scanf("%d",&TabEmploye[i].iAnNais); gotoxy(72,11); scanf("%d",&TabEmploye[i].iMoisNais); gotoxy(75,11); scanf("%d",&TabEmploye[i].iJourNais); fflush(stdin); gotoxy(8,13); gets (TabEmploye[i].sVille); fflush(stdin); gotoxy(30,13); gets (TabEmploye[i].sProv); gotoxy(60,13); scanf("%f",&TabEmploye[i].fTauxHre); gotoxy(14,15); scanf("%f",&TabEmploye[i].sCodPost); fflush(stdin); gotoxy(35,15); scanf("%d",&TabEmploye[i].sCode); gotoxy(39,15); scanf("%d",&TabEmploye[i].sPrem); gotoxy(43,15); scanf("%d",&TabEmploye[i].sFin); gotoxy(20,17); scanf("%d",&TabEmploye[i].fExempFed); gotoxy(61,17); scanf("%d",&TabEmploye[i].fExempPro); pFichier = fopen("EMPLOYE.DAT", "w"); fputs (TabEmploye[i]); CalculerPaye(); } }
fputs needs the file that you're sending the string to. Something like:
BTW, for future reference, don't use non-standard functions if you don't have to.Code:fputs(TabEmployee[i],pFichier);
you're right, I've posted to fast. With
I got the following messageCode:fputs(TabEmployee[i],pFichier);
And for the non-standart library, I totally agree with you, but since in work in command windows, I don't really have the choice yo use non standard library.Code:539 H:\420-2pf\Projet.cpp cannot convert ` AjouterEmploye()::EMPLOYE' to `const char*' for argument `1' to `int
> gotoxy(43,15);
> scanf("%d",&TabEmploye[i].sFin);
Remove all the gotoxy() stuff until you've finished the core logic of the problem.
Until then, it's
- a distraction for you as you keep editing the positions as you change the code.
- useless to us as many can't even compile your non standard code.
When everything works, then you can spend the last hour just putting in all the gotoxy() in the right places, and simply re-testing to make sure it still works.
Also, it was only necessary to have a couple of fields in the struct to prove the point, not 20 of them.
> fflush(stdin);
See the FAQ
Then use fgets() + sscanf() - or better yet, one of strtod() or strtol()
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.
Ok, thanks for the info. Unfortunatly, I don't really know what's non-stantard (except what you're telling me)since my teacher know nothing of C and she dosn't care at all about standard program. I trully appreciate your help by the way.
remove conio.h if you have in your code and see what functions will be noted in warnings saying gotoxy has no prototype... commant this functions out... (has some side effect - if you forget to include some standard header for any other standard function you use)
or find some online C-reference and check each function you use - there.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Well, most compilers would warn you about unprototyped functions, but I'm not sure that whatever the OP's using to compile that code would.
Your non-standard functions are gotoxy() and clrscr(). And fflush(stdin) as well as gets() are both very bad ideas.
If a function you use is not on this list, it's probably not standard: http://cppreference.com/all_c_functions.html
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.