So anyway here's the code. I type 1 and it skips the input for the reverse string. please note this is a friend's code, i don't even do this subject but its always interesting to know why. I did a packet sniffer program in C last semester and came across similar errors but never knew EXACTLY why.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define strLength 120
int main()
{
while (1)
{
menu();
}
return;
}
int menu()
{
//variables
int nChoice;
int n;
int x;
int fibCount;
printf("\n\nChoose an Option.\n");
printf("--------------------\n\n");
printf("1. Reverse a String\n");
printf("2. Fibonacci Sequence\n");
printf("3. Get Statistics on a String\n");
printf("4. Play Extended Tic-Tac-Toe\n");
printf("5. Exit the Program\n\n");
printf("Input Choice: ");
scanf("%d", &nChoice);
switch(nChoice)
{
case 1 : printf("\nYou chose Option 1: Reverse a String.\n");
printf("---------------------------------------\n\n");
RevString();
break;
case 2 : printf("\nYou chose Option 2: Fibonacci Sequence.\n");
printf("---------------------------------------\n\n");
do
{
printf("How many numbers would you like displayed? (between 1 and 100): ");
scanf("%d", &n);
}while(n < 1 || n > 100);
for(n = 0; n < fibCount ; n++)
{
x=Fib(n);
printf("%d ", x);
}
break;
case 3 : printf("\nYou chose Option 3: Statistics of a String.\n");
printf("-------------------------------------------\n\n");
StatString();
break;
case 5 : printf("\nThank You for using this Program.\n");
printf("---------------------------------\n\n");
exit(0);
default: printf("Incorrect input.\n");
printf("--------------\n\n");
menu();
}
}
int RevString()
{
char str[strLength];
char revStr[strLength];
int i = 0;
int j = 0;
printf("Enter the string to be reversed: \n\n");
fgets(str, 120, stdin);
for(i = strlen(str) - 1; i >= 0; i--)
{
revStr[j] = str[i];
j++;
}
revStr[j] = '\0';
printf("You inputted: %s\n", str);
printf("Input reversed: %s\n", revStr);
return;
}