fork(1) download
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct item{
  5. char name[50];
  6. int id;
  7. char cat[50];
  8. union data{
  9. int warrenty;
  10. char size[50];
  11. }data1;
  12. };
  13.  
  14. int main()
  15. {
  16. struct item store[5];
  17.  
  18. for(int i = 0; i < 2; i++)
  19. {
  20. printf("Name: ");
  21. gets(store[i].name);
  22. printf("ID: ");
  23. scanf("%d", &store[i].id);
  24. printf("Category: ");
  25. gets(store[i].cat);
  26. if(strcmp(store[i].cat,"Electronics") == 0)
  27. scanf("%d", &store[i].data1.warrenty);
  28. else if(strcmp(store[i].cat,"Clothing") == 0)
  29. scanf(store[i].data1.size);
  30. }
  31.  
  32. }
  33.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Name: ID: Category: Name: ID: Category: