fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Photo;
  6.  
  7. typedef struct
  8. {
  9. char user[50];
  10. char password[50];
  11. struct Photo *photohead;
  12. }User;
  13.  
  14. typedef struct Photo
  15. {
  16. int id;
  17. char des[50];
  18. char name[50];
  19. char place[50];
  20. char date[50];
  21. struct photo *next;
  22. struct Photo *prev;
  23. }Photo;
  24.  
  25. User *CreateArray();
  26. User *CreateArray(int size)
  27. {
  28. int i;
  29. User *Userlist;
  30. FILE *fp;
  31. fp=fopen("clients.txt","r");
  32. if(fp==NULL){printf("failed to open file");}
  33. Userlist=malloc(size*sizeof(User));
  34. for(i=0;i<size;i++)
  35. {
  36. fscanf(fp,"%s %s",Userlist[i].user,Userlist[i].password);
  37. Userlist[i].photohead=(Photo*)malloc(sizeof(Photo));
  38. Userlist[i].photohead=NULL;
  39. }
  40.  
  41. fclose(fp);
  42. return Userlist;
  43. };
  44.  
  45. void option1(Photo **head,char name[50],char date[50],
  46. char description[50],char location[50])
  47. {
  48.  
  49. Photo *temp;
  50. temp=(Photo*)malloc(sizeof(Photo));
  51. temp=head;
  52. while(temp->next!=NULL)
  53. {
  54. temp=temp->next;
  55. }
  56.  
  57. temp->next=(Photo*)malloc(sizeof(Photo));
  58. strcpy(temp->next->name,name);
  59. strcpy(temp->next->date,date);
  60. strcpy(temp->next->des,description);
  61. strcpy(temp->next->place,location);
  62.  
  63. }
  64.  
  65. int main()
  66. {
  67. char name[50],date[50],description[50],location[50];
  68. int option,user,sizze;
  69. User *Users;
  70. sizze=sizeofArray();//gets the size that the array needs to be from the file
  71. Users=CreateArray(sizze)
  72. PrintArray(Users,sizze);
  73.  
  74. printf("Enter the photos details\n");
  75. printf("Photos name:");
  76. scanf("%s",&name);
  77. printf("\n");
  78. printf("Photos date:");
  79. scanf("%s",&date);
  80. printf("\n");
  81. printf("Photos description:");
  82. scanf("%s",&description);
  83. printf("\n");
  84. printf("Photos location:");
  85. scanf("%s",&location);
  86. printf("\n");
  87. option1(&Users[user].photohead,name,date,description,location);
  88. }
  89.  
  90.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'option1':
prog.c:51:8: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
    temp=head;
        ^
prog.c:54:11: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
       temp=temp->next;
           ^
prog.c:57:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
    temp->next=(Photo*)malloc(sizeof(Photo));
              ^
prog.c:58:21: error: dereferencing pointer to incomplete type 'struct photo'
    strcpy(temp->next->name,name);
                     ^
prog.c: In function 'main':
prog.c:70:10: warning: implicit declaration of function 'sizeofArray' [-Wimplicit-function-declaration]
    sizze=sizeofArray();//gets the size that the array needs to be from the file 
          ^
prog.c:72:7: error: expected ';' before 'PrintArray'
       PrintArray(Users,sizze);
       ^
prog.c:76:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
    scanf("%s",&name);
          ^
prog.c:79:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
    scanf("%s",&date);
          ^
prog.c:82:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
    scanf("%s",&description);
          ^
prog.c:85:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
    scanf("%s",&location);
          ^
prog.c:68:8: warning: unused variable 'option' [-Wunused-variable]
    int option,user,sizze;
        ^
stdout
Standard output is empty