晚上被这个内存扩展崩溃的问题折腾的有点崩溃,当答案揭晓的那一刻,恍然大悟,原来如此简单。
练习题目:输入一个字符串,根据字母进行排序,说白了就是一个简单的冒泡
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define BUF_LEN 100
#define COUNT 5
int main(void)
{
char buf[BUF_LEN];
size_t str_count = 0;
size_t capacity = COUNT;
char **pS = calloc(capacity, sizeof(char*));
char **psTemp = NULL;
char *pTemp = NULL;
size_t str_len = 0;
bool sorted = false;
printf("Enter strings to be sorted, one per line. Press Enter to end:\n");
char *ptr = NULL;
while(true)
{
ptr = fgets(buf, BUF_LEN, stdin);
if(!ptr)
{