lab8
This commit is contained in:
+4
-114
@@ -1,12 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
#include "./func/func.h"
|
||||
|
||||
int main() {
|
||||
int enter,
|
||||
@@ -21,7 +13,8 @@ int main() {
|
||||
printf("\tMassive manipulation\n");
|
||||
printf("a. SetMassiveSize\n");
|
||||
printf("b. FillMassive\n");
|
||||
printf("c. ViewMassive\n\n");
|
||||
printf("c. ViewMassive\n");
|
||||
printf("d. SelectFunc\n\n");
|
||||
printf("\tExit - g\n\n\n");
|
||||
enter = getchar();
|
||||
if(flush())return 1;
|
||||
@@ -42,7 +35,7 @@ int main() {
|
||||
break;
|
||||
|
||||
case'd':
|
||||
if(massCreated){selfunc(massive);flush;}
|
||||
if(massCreated){selfunc(massSize,massive);flush();}
|
||||
else printf("\n\tFill Massive first.\n\n");
|
||||
break;
|
||||
|
||||
@@ -54,106 +47,3 @@ int main() {
|
||||
}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 == '-' && e==0 && massive[i]==0)))
|
||||
{
|
||||
if (x == 'e')e1=1;
|
||||
else if (x == '-')minus=1;
|
||||
|
||||
else if (e1) e = (e*10)+(x-'0');
|
||||
else massive[i] = (massive[i]*10) + (x-'0');
|
||||
}
|
||||
|
||||
if(x == EOF || x == 3){return 0;}
|
||||
if(e1&&minus)minus=0;
|
||||
if(minus && (x == '\n' || x == ' ')){minus = 0; massive[i]*=-1;}
|
||||
if(e>size) {printf("e is out of range.\n");i=p;}
|
||||
else if(e1) {i = e - 1;putchar('\n');}
|
||||
if(x == 'g'){return 1;}
|
||||
if((x<='0' && x>='9')||x==' '||x=='\n'||x>=32);
|
||||
else {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%p\t%d\n",i,&massive[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){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int flush(void){
|
||||
int x;
|
||||
while((x = getchar())!='\n' && x!=4 && x!=1)
|
||||
if(x==EOF)return 1;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user