Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define TAILLE_MAX 1024
- struct contact
- {
- char *firstname;
- char *lastname;
- int age;
- };
- int suite(void)
- {
- FILE* fichier = NULL;
- char *chaine = malloc(sizeof(char) * 45);
- int nbcontact = 0;
- fichier = fopen("contact.txt", "r");
- if (fichier != NULL)
- {
- while (fgets(chaine, TAILLE_MAX, fichier) != NULL)
- {
- printf("%s", chaine);
- nbcontact++;
- }
- printf("\n%d contact(s)\n", nbcontact);
- fclose(fichier);
- }
- else
- return 1;
- return 0;
- }
- int main()
- {
- char nom[20];
- char prenom[20];
- char age[3];
- char string[45];
- struct contact individu;
- FILE *fichier=NULL;
- fichier=fopen("contact.txt","a+");
- printf("Entrez votre prenom\n");
- scanf("%s",&prenom);
- printf("Entrez votre nom\n");
- scanf("%s",&nom);
- printf("Entrez votre age\n");
- scanf("%s",&age);
- individu.firstname=&prenom;
- individu.lastname=&nom;
- individu.age=&age;
- strcat(prenom," ");
- strcat(nom," ");
- strcat(string,individu.firstname);
- strcat(string,individu.lastname);
- strcat(string,individu.age);
- strcat(string,"\n");
- fputs(string,fichier);
- fclose(fichier);
- suite();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement