#include "framework.h"
#include <stdio.h>
//-----------------------------------------------------------------------------
// Computes and returns the length of a string
//
// @param text string to check
//
// @return length of the string
//
int stringLength(char *text);
//-----------------------------------------------------------------------------
// Changes a string to upper case
//
// @param text string to modify
//
void toUpper(char *text);
//-----------------------------------------------------------------------------
int stringLength(char *text)
{
int string_length = 0;
while (text[string_length] != '\000')
string_length++;
return string_length;
}
// Main Function
//
int main()
{
char key[MAX_KEY_LENGTH] = {};
int string_len = 0;
do {
printf(KEY_PROMPT);
gets(key);
string_len = stringLength(key);
if (string_len <= MAX_KEY_LENGTH && string_len > 0)
{
break;
}
} while (string_len > MAX_KEY_LENGTH || string_len < 0);
}
This is my code. Always when i first put in a string thats too long (eg. "Student StudentStudent StudentStudent StudentStudent StudentStudent Student") and then one which is "correct" (eg. "Student Student")
it gives me this error: (look at picture)