Quote Originally Posted by Paul McKenzie View Post
As to your code:
Code:
 const char * getServer(char *svrList)
{
    char temp[512];
    strcpy (temp,svrList);
What if svrList points to a string that is more than 512 bytes? What if I pass a NULL to getServer()? Your code is now broken.
Code:
	//return "0";
What is returned if the code falls through to this line that you commented out? The return value is now undefined.

Regards,

Paul McKenzie
As far as the more than 512 bytes, for what I am doing in this program and knowing that arrays cannot be dynamic in nature for 'C', I think my best bet is to just control the data that is in that array to make sure that a NULL or more than 512 bytes are not fed into the function. I know this is not the best way, but for this assignment, it will get me by.

Sorry about that, I changed it to return NULL; and changed my if statement below that.
As of right now, everything is working and the debugger helped a great deal! The only issue I am having now is:


I can't get this loop to break when I enter "N" at the prompt. It seems to completely skip the if true and false values and just continue running the while(1) loop. Am I missing something simple? I am just trying to continue the loop until the user enters anything other than Y or y. In the debugger, the value is getting put in "cont", but it just skips the continue or break on that if statement.


Code:
while(1)
    {
	printf("Checking which server to use.\n");
	if (getServer(svrList) != "0")
	{
		server_name= getServer(svrList);
		printf("The server is %s\n",server_name);
		printf("Do you want to continue? [Y/N]");
		fscanf(stdin,"%s", &cont);
		printf("%s\n", &cont);
	if (cont = "Y" || "y")
		continue;
			else
			break;
	}
	else
		{
		printf("There are no available servers!\n");
		break;
		}
		
	return 0;
}