当新大小小于缓冲区的旧大小时, string alt;
bool firstRun = true;
do
{
if (firstRun)
{
firstRun = false;
GameLogic();
}
Console.WriteLine("Play again?");
Console.WriteLine("[Y]es | [N]o");
alt = Console.ReadLine();
alt.ToLower();
if (alt == "Y" || alt == "y")
{
Console.Clear();
GameLogic();
}
else if (alt == "N" || alt == "n")
{
break;
}
else
{
Console.WriteLine("Invalid input!");
}
} while (alt != "N" || alt != "n");
Console.WriteLine("\nPress any key to quit...");
Console.ReadKey();
是否有可能失败?在此示例中,缓冲区的大小从100字节调整为50字节。
realloc