I have a simple program (code follows) that circle_shifts an array, but I need it to be able to quit when the user enters a character, (ex. q). Where do I start?
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int printAr(int n[], const int SIZE){
unsigned int i;
printf("Array contents: ");
for( i=0 ; i<SIZE ; i++ ){
printf("%d ", n[i]);
}
printf("\n");
}
int shifty(int userAns, int n[], const int SIZE){
int i, j; //counter
int temp_pivotNum;
for( j=0 ; j<(sqrt(userAns*userAns)) ; j++ ){
if( userAns >= 0 ){
temp_pivotNum = n[SIZE-1];
for( i=(SIZE-1) ; i>0 ; i-- ){
n[i] = n[i-1];
}
n[0] = temp_pivotNum;
}
else{
temp_pivotNum = n[0];
for( i=0 ; i<(SIZE-1) ; i++ ){
n[i] = n[i+1];
}
n[SIZE-1] = temp_pivotNum;
}
}
}
int main(){
const int SIZE = 10;
int n[SIZE], i, userNum;
int userAns;
for( i=0 ; i<SIZE ; i++ ){
n[i] = i+1;
}
printAr(n, SIZE);
while( 1 ){ //while(1) is temporary
printf("Shift how many positions? ");
scanf("%d", &userAns);
shifty(userAns, n, SIZE);
printAr(n, SIZE);
}
}