Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define TAILLE_MAX 1024
  5.  
  6. struct contact
  7. {
  8. char *firstname;
  9. char *lastname;
  10. int age;
  11.  
  12. };
  13.  
  14. int suite(void)
  15. {
  16. FILE* fichier = NULL;
  17. char *chaine = malloc(sizeof(char) * 45);
  18. int nbcontact = 0;
  19.  
  20. fichier = fopen("contact.txt", "r");
  21.  
  22. if (fichier != NULL)
  23. {
  24. while (fgets(chaine, TAILLE_MAX, fichier) != NULL)
  25. {
  26. printf("%s", chaine);
  27. nbcontact++;
  28. }
  29. printf("\n%d contact(s)\n", nbcontact);
  30. fclose(fichier);
  31. }
  32. else
  33. return 1;
  34. return 0;
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40. char nom[20];
  41. char prenom[20];
  42. char age[3];
  43. char string[45];
  44. struct contact individu;
  45.  
  46. FILE *fichier=NULL;
  47. fichier=fopen("contact.txt","a+");
  48.  
  49. printf("Entrez votre prenom\n");
  50. scanf("%s",&prenom);
  51. printf("Entrez votre nom\n");
  52. scanf("%s",&nom);
  53. printf("Entrez votre age\n");
  54. scanf("%s",&age);
  55.  
  56. individu.firstname=&prenom;
  57. individu.lastname=&nom;
  58. individu.age=&age;
  59.  
  60. strcat(prenom," ");
  61. strcat(nom," ");
  62. strcat(string,individu.firstname);
  63. strcat(string,individu.lastname);
  64. strcat(string,individu.age);
  65. strcat(string,"\n");
  66.  
  67. fputs(string,fichier);
  68. fclose(fichier);
  69. suite();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement