I'm teaching myself C atm, reading online tutorials and doing exercises at the end of the chapters. What I've written is a program that reads in either check/deposit and adjusts the amount in the bank account. For example, deposit 1000, deposits 1000 in the bank.

Explanation of some of the code:

The function separator is used to separate the command "deposit/check" from the amount to deposit. How it does this is it will scan the input string for letters and put it in a char array. To scan the amount to deposit in the same line, the loop also searches for char numbers and converts it to an int within the same loop. The function also compares user input to the strings "check" and "deposit".

The function mystrcmp works like strcmp.

Here is the code:
Code:
#include <stdio.h>

int bankAccount = 1000;

main()
{
	int i, c;
	char input[25];
	
	while ( 1 )
	{
		printf("Enter a check or deposit with the amount or 'q' to quit: ");	
		
		if ( (c = getchar() ) == 'q' )
			break;
		
				
		getLine( input, 25 );		        //gets input
		separator( input );		        //separates command and amount
		
		printf("Balance: %d\n", bankAccount);   //prints the balance after each loop
		
	}
}

//Reads the input line
int getLine( char array[], int max )
{
	int i = 0; 				        //incrementer
	int c;					        //holds char
	max = max - 1;					//for null zero
	
	while ( (c = getchar() ) != EOF )
	{
		if ( c == '\n')				//if end of line, break
			break;
		if ( i < max )				//if less than max, put in array
		{
			array[i] = c;
			i++;
		}
		
		if ( (c == EOF) && (i == 0) )
			return EOF;
		
	}
	
	array[i] = '\0';				
	return i;
}


int separator( char array[] )
{
	char command[20];				//will hold either deposit or check
	char amount[20];				//holds amount, but in char
	char deposit[] = "deposit";				
	char check[] = "check";			
	int i, digit, num, retVal = 0;

	for ( i = 0; array[i] != '\0'; i++ )
	{
		if ( array[i] >= 97 && array[i] <= 127 )	//if between a-z, no caps
		{
			command[i] = array[i];		        //put letter in array
			printf("Entered %s\n", command);
		}
		if ( array[i] >= 48 && array[i] <= 57 )		//if between 0-9
		{
			amount[i] = array[i];
			digit = amount[i] - '0';	        //converts character int to
			retVal = retVal*10 + digit;	        //actual int, i.e. '123' 
		 }                                                    					   
	}

	printf("Entered %s\n", command);			//test commands to debug
	printf("Entered %d\n", retVal);			        //test commands to debug

	if ( mystrcmp( command, deposit ) == 0 )
	{
		bankAccount = bankAccount + retVal;	        //add to bank account 
	}
	
	if ( mystrcmp( command, check ) == 0 )
	{
		bankAccount = bankAccount - retVal;	        //subtract from bank
	}
		
	return 0;
}

//This is my personal string comparison function.
mystrcmp(char str1[], char str2[])					
{
	int i = 0;

	while(1)
	{
		if(str1[i] != str2[i])
			return str1[i] - str2[i];
		if(str1[i] == '\0' || str2[i] == '\0')
			return 0;
		i++;
	}
}
So my problems are:

1) The if statement to quit the program reads the first letter and if it is 'q', then the program exits. But what happens is that if I type "deposit", it reads the first char 'd' and then passes off 'eposit' to the function below. How do I overcome this?

2) I have no idea what's going on here, command[20] does not work, but command[10] does. Must be something with the length of the array.
Here is an output with command[20]:
Enter a check or deposit with the amount: check 1000
Entered cX���
Entered ch���
Entered che��
Entered chec�
Entered check
Entered check
Entered 1000
Balance: 1000


Here is an output with command[10]:
Enter a check or deposit with the amount: check 1000
Entered c
Entered ch
Entered che
Entered chec
Entered check
Entered check
Entered 1000
Balance: 0



I think what I've done here is make a simple program overcomplicated. Nevertheless, I would like to debug it first, then rewrite the code so that it's more logical.

Thanks for taking the time to read this.