My problem is when i try to include the function funcString in my code and try to built it , i get this errors:
error C2065: 'ch' : undeclared identifier
And when i remove the function funcString i don't get any error and the programs runs perfectly.
HERE is my code i wrote with function funcString included in the code.
#include "stdafx.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void load_menu(void);
void funcChar(void);
void funcString(void);
void funcFloat(void);
void funcInteger(void);
void funcDisplay(void);
int main(int argc, char** argv)
{
// initializeUart0BaudRate(9600);
// initializeUart0Tx();
// initializeUart0Rx();
load_menu();
return 0;
}
void load_menu(void)
{
int choice;
do
{
printf("\n\n**** MAIN MENU ****\n\n");
printf("1. Enter a char\n");
printf("2. Enter a string\n");
printf("3. Enter a float\n");
printf("4. Enter an integer\n");
printf("5. Display the square of numbers from 1-100\n");
printf("9. Quit the Program\n\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: funcChar();
break;
case 2: funcString();
break;
case 3: funcFloat();
break;
case 4: funcInteger();
break;
case 5: funcDisplay();
break;
case 9: printf("Quitting program!\n\n");
break;
default: printf("Invalid choice! Choose Again.\n");
break;
}
} while (choice != 9);
}
void funcChar(void)
{
char myChar;
int ch;
printf("\nEnter a letter: ");
getchar();
scanf("%c",&myChar);
/* Flushes input buffer from the newline from scanf() */
while ( (ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ( (ch = getchar()) != '\n' && ch != EOF);
return;
}
void funcString(void)
{
char myString[50];
int i;
printf("Enter you name: ");
scanf("%s", myString);
for (i=0; i<strlen(myString); i++)
{
putchar(toupper(myString[i]));
}
for (i=0; i<strlen(myString); i++)
{
putchar(tolower(myString[i]));
}
/* Flushes input buffer from the newline from scanf() */
while ( (ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ( (ch = getchar()) != '\n' && ch != EOF);
return;
}
void funcFloat(void)
{
float myFloat;
int ch;
printf ("\nEnter a decimal number: ");
scanf ("%f", &myFloat);
printf ("You entered: %.2f\n", myFloat);
if (myFloat<0)
{
printf ("You entered a negative number.\n\n");
}
else
{
printf ("You entered a positive number.\n\n");
}
/* Flushes input buffer */
while ((ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ((ch = getchar()) != '\n' && ch != EOF);
return;
}
void funcInteger(void)
{
int myInt;
int ch;
printf ("\nEnter an integer/a number: ");
scanf ("%i", &myInt);
if (myInt<0)
{
printf ("You entered a negative number.\n\n");
}
else
{
printf ("You entered a positive number.\n\n");
}
/* Flushes input buffer */
while ((ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ((ch = getchar()) != '\n' && ch != EOF);
return;
}
void funcDisplay(void)
{
int num;
int ch;
for(num=1;num<101;num=num+1)
{
printf("Square of %i is: %i\n", num, num*num);
}
/* Flushes input buffer */
while ((ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ((ch = getchar()) != '\n' && ch != EOF);
return;
}