-1
1) Create a program that has a character array. This vector must have a maximum size TAM = 10. No parameter can be global.
The program must have:
a. the main function, responsible for interacting with the user, informing the results of the operations of the other functions
b. a "insert character" function. It must request the character from the user, and insert it into the vector, in the first empty position, if it still has space. Must return if inserted or not.
c. A "character swap" function. This function requests a new character from the user. The function must search in the vector the first character that is larger than the given character, when find, do the switch. The function must return whether there was the switch or not. When there is the switch, the main function (main) must be able to print which character came out of the vector.
d. A function to remove characters. The deletion must be logical at the end of the array. Simply decrement the top.
e. A function to list characters.
f. a function that prints each of the distinct characters and the number of times it appears in the array
I’m trying to create this program in C gives question above, but I’m having trouble passing the flag back to main, the character returns at point 0 of the array, but the flag does not return as 1.
That’s the code I’ve written so far.
void insere(int array[],int n, int flag);
int main(){
int array[10], n=0, flag=0;
insere(array, n, flag);
printf("%d", flag);
if(flag==1){
printf("numero inserido");
}
return 0;
}
void insere(int array[], int n, int flag){
int i;
printf("insira um numero: ");
for(i=n; n<10; n++){
scanf("%d", &array[i]);
}
flag =1;
return flag;
}