- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sysexits.h>
- #define MAX_NAMES 10000
- #define MAX_NAME_LEN 40
- void writefile(char c[100]);
- void sortstrings(void *array, size_t s);
- int compare(const void *a, const void *b);
- int main(int argc, char *argv[] )
- {
- char c[100];
- FILE *pFile;
- long lFileLen;
- int n;
- size_t str_length =0;
- if(argc != 3) // we need 3 things passed in, if not then it wont work
- {
- printf("usage: %s readfile writefilen",argv[0]);
- }
- else
- {
- printf("we made it this far");
- // assume arg[1] is a file
- FILE *dataout;
- dataout = fopen(argv[2], "a+" );
- pFile = fopen(argv[1], "rw" );
- if(pFile == NULL)
- {
- printf("couldnt open the filen");
- printf("%sn",argv[1]);
- return 1;
- }
- else
- {
- // lets get the data stored..
- n = fread(c, 1, 50, pFile);
- c[n] = ' ';
- str_length = strlen(c);
- printf("size of strings %i",str_length);
- sortstrings(c, str_length);
- }
- if(dataout == NULL)
- {
- printf("couldnt open the filen");
- printf("%sn",argv[2]);
- return 1;
- }
- else
- {
- fwrite(c, str_length, 1, dataout);
- fclose(dataout);
- fclose(pFile);
- return(0);
- }
- }
- }
- int compare(const void *a, const void *b)
- {
- return strcmp(*(char **)a, *(char **)b);
- }
- void sortstrings(void *array, size_t s)
- {
- qsort(array, s, sizeof(char *), compare);
- }
sort problem
By: microhaxo | Date: Feb 24 2010 00:21 | Format: None | Expires: never | Size: 1.41 KB | Hits: 996
Latest pastes
18 hours ago
21 hours ago
1 days ago
2 days ago
2 days ago