devxlogo

Writing and deleting text file lines, and bubble sorting alphabetically

Writing and deleting text file lines, and bubble sorting alphabetically

Question:
How can I write and delete individual lines of a text file?Also, how can I bubble-sort the whole text file alphabetically?

Answer:
There is no support in thelanguage to do either of these things.

However, there are many tricks that one can perform to make them happen. One is to handle all manipulations to the file in memory, then write the fileafter it has been manipulated. Here is an example of a function that deletes some lines from a file and writes it back.

#include #include void deleteLine(char *lines[],int lineNo){	lines[lineNo-1][1] = ‘

devx-admin

Share the Post: