Public feed #600326

Something

public c v1 · immutable
Raw Edit
·published 2007-07-02 19:27 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>int main(void){    char string[256] = { 0 };    char *pstring[10] = { NULL };    char *ptemp = NULL;    bool sorted = false;    int index = 0;        // get string input        while(*fgets(string, sizeof string, stdin) != '\n')    {        pstring[index] = (char *)malloc(sizeof string);        strcpy(pstring[index++], string);    }        // sort the strings after length    do    {        sorted = true;                for(int i = 0; i < index; i++)        {            if(strlen(pstring[i]) > strlen(pstring[i + 1]))            {                sorted = false;               }        }            } while(!sorted);        // write out the sorted strings and free the memory    for(int i = 0; i < index; i++)    {        printf("%s", pstring[i]);        free(pstring[i]);    }            return 0;}