Alphabetize C functions in .c file?
I have a zillion functions and I'd like to get them in alphabetical order.
Header = easy. C source file ... Google is failing me.
Moderator: Inside3D Admins
#include<iostream>
#include<cstring>
#include<fstream>
using namespace std;
void sortString(char array[], int num);
void outputString(char array[], int num);
int main() {
int columns=30, rows=0;
char filename[30], letter;
ifstream fin;
cout << "Enter the file name: ";
cin >> filename;
fin.open(filename);
if (!fin) {
cout << "Failure to open the file.";
} else {
while (fin >> letter) {
if (letter == '\n')
rows++;
}
fin.clear();
fin.seekg(0,ios::beg);
char name[rows][columns];
rows = 0;
while (fin.get(name[rows][columns])) {
rows++;
}
sortString(name, rows+1);
outputString(name, rows+1);
}
return 0;
}
void sortString(char array[], int num) {
int i, j;
char check[num][30];
for (i=1; i<num; i++) {
strcpy(check, array[i][30]);
for (j=1; j>=1 && (strcmp(check, array[30][j-1])==1); j--) {
array[j][30] = array[j-1][30];
array[j-1][30] = check;
}
}
}
void outputString(char array[], int num) {
for (int i=0; i<num; i++) {
cout << array[i][30] << endl;
}
}reckless wrote:besides that yeah probably better to write your own
// Do not put zero length strings through to this function
char* SortedText_FromText_Alloc (const char* originalText, const char delimChar1, const char delimChar2)
{
const size_t buffersize = strSizeToDuplicate (originalText);
char* newText = Memory_calloc (1, buffersize, "Sorted text out");
int numBlocks = 0;
textSort_t* FirstBlock = TextSort_calloc_On_Text_As_Zero_Length (originalText, 0, &numBlocks);
textSort_t* alphaBest = NULL;
do
{
// Phase 1. Locate breaking points. After every "}"
const fbool asBlocks = !delimChar2;
int curlyBracketDepth = 0; // For AsBlocks mode
textSort_t* previousBlock = FirstBlock;
textSort_t* currentBlock;
for (int i = 0; originalText[i]; i ++)
{
const char myChar = originalText[i];
// To do ... honor "//" comments through end of a line Maybe fbool isInNewLineComments and only check for end of sequence
// To do ... honor "/*" comments through "*/" Maybe fbool isInAsteriskComments and only check for end of sequence
do
{
if (asBlocks == True && myChar != delimChar1) break; // No delim found
if (asBlocks && myChar != delimChar1 && myChar != delimChar2 ) break; // No delim found
if (asBlocks == True)
{
curlyBracketDepth += myChar == delimChar1 ? 1 : -1; // If delim1 + 1, if delim2 -1 to level
if (curlyBracketDepth > 0) break; // No split
}
// Split!
currentBlock = TextSort_New_Block_Text_At_X_With_Close_Old (originalText, i, previousBlock, &numBlocks);
} while (0);
}
// Finalize current block
TextSort_Finalize_With_Stop_And_Next ( currentBlock, strlen(originalText), NULL); // currentBlock.stop = i - 1; // End of string before null terminator
} while (0);
do
{
// Stage 2: Sort those functions ... move through each cursor and run down the alphaSorted link list
// One cursor at a time slides down the alpha sort
for (textSort_t* newEntry = FirstBlock; newEntry; newEntry = newEntry->allocNext)
{
textSort_t* previousAlphaCursor;
// Head of list scenarios. List is empty or higher alphabetically than head of the list
if (alphaBest == NULL || TextSortAutoNCompare (originalText, newEntry, alphaBest) < 0 )
{
newEntry->alphaNext = alphaBest; // Tell item it is after me alphabetically
alphaBest = newEntry; // Assume head of list position
continue; // Get out. Do next item.
}
do
{ // Find position in list
textSort_t* previousAlphaCursor = alphaBest;
textSort_t* alphaCursor = alphaBest->alphaNext;
// Stop when we hit first item that we are alphabetically higher than
for (; alphaCursor && TextSortAutoNCompare (originalText, newEntry, alphaCursor) > 0; previousAlphaCursor = alphaCursor, alphaCursor = alphaCursor->alphaNext);
// When we come out of the for loop, we have the right insertion position or NULL
newEntry->alphaNext = alphaCursor;
previousAlphaCursor->alphaNext = newEntry;
} while (0);
}
// We should have a nice linked list at this point
} while (0);
do
{
// Reconstruct string by running through linked list. Advance cursor
size_t textCursor = 0;
for (textSort_t* linkCursor = alphaBest; linkCursor; linkCursor = linkCursor->alphaNext);
StringRangeCopyIntoAtMoveCursor (originalText, linkCursor->startOffset, linkCursor->length, newText, &textCursor);
// String should be reconstructed now
} while (0);
do
{
textSort_t* linkCursor = FirstBlock;
for (textSort_t* nextLink = linkCursor->nextAlloc; linkCursor; linkCursor = nextLink, nextlink = linkCursor->next);
Memory_free(linkCursor);
} while (0);
return newText; // Calling function has responsibility free it
}
Base navigation
-------------------
Generic keypress. Enter keypress.
Left Arrow, Right Arrow
Up Arrow = Same offset within one row higher, downarrow same
home. Beginning of line. End. End of line.
ctrl-home. Beginning of file. Ctrl-end. End of file.
alt-arrow. Next word.
Shift select.
paste. insert
display special characters
windowing
-------------------
Cursor pos.
Cursor down, up, left, right
Page up, page down
Insert mode, delete
Beginning of file, end of file
Sort lines
Selection
Behavior of tab?
Search
Replace
Window (Top, bottom, left, right)
Search. Replace.
Find in files (what where). (path, pattern,
Users browsing this forum: No registered users and 2 guests