diff --git a/proglabs/lab8/code.c b/proglabs/lab8/code.c new file mode 100644 index 0000000..db9d512 --- /dev/null +++ b/proglabs/lab8/code.c @@ -0,0 +1,158 @@ +#include +#define MAXMASSIVESIZE 10000 + + +void setmass(int *massSize); +int fillmass(int massSize, int *massive); +void viewmass(int massSize, int *massive); +void selfunc(int massive[]); +int flush(void); + +int main() { + int enter, + q = 1, + massSize = 0, + massCreated = 0, + massive[MAXMASSIVESIZE]; + printf("Test massives and pointers\n"); + + do{ + printf("\t\tMain menu\n"); + printf("\tMassive manipulation\n"); + printf("a. SetMassiveSize\n"); + printf("b. FillMassive\n"); + printf("c. ViewMassive\n\n"); + printf("\tExit - g\n\n\n"); + enter = getchar(); + if(flush())return 1; + switch(enter){ + case'a':case'A': + setmass(&massSize); + break; + + case'b':case'B': + if(massSize!=0){massCreated = fillmass( + massSize,massive);flush();} + else printf("\n\tSet massive size first.\n\n"); + break; + + case'c':case'C': + if(massCreated){viewmass(massSize,massive);} + else printf("\n\tFill Massive first.\n\n"); + break; + + case'd': + if(massCreated){selfunc(massive);flush;} + else printf("\n\tFill Massive first.\n\n"); + break; + + case'g':case'G': + q=0;break; + + default: printf("Input Err\n\n");break; + } + }while(q); + return 0; +} + + +void setmass(int *massSize){ + printf("\t\tSetMassiveSize\n"); + printf("Set Massive Size - input integer\n"); + printf("Exit from this menu - input 0\n\n\n"); + printf("Input: "); + int n; + while(scanf(" %d",&n)!=1||n>MAXMASSIVESIZE){ + if(flush())return; + flush(); + if(n>10000)printf("Input cannot be >%d",MAXMASSIVESIZE); + printf("Input Err\nInput: "); + } + + flush(); + + if(n==0) + return; + else + *massSize = n; + return; +} + +int fillmass(int size, int *massive){ + printf("\t\tFill Massive\n"); + printf("You can devide elements with space or enter.\n"); + printf("You also can decide to from which element start with e.\n"); + printf("To exit input g.\n\n\n"); + printf("Input: "); + + + int x, i, e1,e = 0, p=-1, minus = 0; + + for(i = 0;i < size;i++){ + e1 = e = massive[i] = 0; + while(((x = getchar()) != '\n' && x !=' ' + && x != EOF && x != 4) + && ((x>='0' && x<='9') + || x == 'e' || x == '-')) + { + if (x == 'e')e1=1; + else if (e1) e = (e*10)+(x-'0'); + else if (x == '-' && massive[i]==0)minus=1; + else massive[i] = (massive[i]*10) + (x-'0'); + } + + if(x == EOF || x == 3){return 0;} + if(minus && (x == '\n' || x == ' ')){minus = 0; massive[i]*=-1;} + if(e>size) printf("e is out of range.\n"); + else if(e1) {i = e - 1;putchar('\n');} + if(x == 'g'){return 1;} + if(x!='\n' && x!=' ' && x!='e' && x!='-' && !(x>='0'&&x<='9')) + {while((x=getchar())!='\n'&&x!=' '&&x!=EOF&&x!=4);i--;} + if(p!=i&&e1!=1) + printf("Massive - [%d]\t%d\n",i,massive[i]); + p=i; + } + return 1; +} + + +void viewmass(int size, int *massive){ + printf("\t\tView Massive\n"); + for(int i = 0; i < size; i++){ + printf(" | [%6d]\t%d\n",i,massive[i]); + } +} + + +void selfunc(int *massive){ + printf("\tFunctions\t(my - 7|16|24)\n"); + printf("1. \t2. \t3. \n"); + printf("4. \t5. \t6. \n"); + printf("7. \t8. \t9. \n"); + printf("10. \t11. \t12. \n"); + printf("13. \t14. \t15. \n"); + printf("16. \t17. \t18. \n"); + printf("19. \t20. \t21. \n"); + printf("22. \t23. \t24. \n"); + printf("25. \t26. \t27. \n"); + printf("28. \t29. \t30. \n\n"); + printf("\tExit - 0\n"); + + int n; + while(scanf(" %d",&n)!=1){ + if(flush())return; + printf("Input Err\nInput: ");} + flush(); + return; + switch(n){ + case 1: + + } +} + +int flush(void){ + int x; + while((x = getchar())!='\n' && x!=4 && x!=1) + if(x==EOF)return 1; + return 0; +} diff --git a/proglabs/lab8/tmp.out b/proglabs/lab8/tmp.out new file mode 100755 index 0000000..c9fd6c8 Binary files /dev/null and b/proglabs/lab8/tmp.out differ