Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void bubbleSort(char *pointVet[], int size);
- void archiveGen(char *pointVet[], int size);
- void archiveLoad(char *pointVet[])
- int main() {
- int size,i = 0,j;
- FILE *fp;
- char *token;
- fp = fopen("nomes.txt","r");
- fscanf(fp,"%d",&size);
- char *pointVet[size];
- for(i = 0; i < size; i++){
- fscanf(fp,"%s",token);
- pointVet[i] = (char*)malloc(sizeof(char)*strlen(token));
- strcpy(pointVet[i],token);
- }
- fclose(fp);
- bubbleSort(pointVet,size);
- archiveGen(pointVet,size);
- return 0;
- }
- void bubbleSort(char *pointVet[], int size){
- int i,j;
- char *token;
- for(i = 0; i < size; i++){
- for(j = 0; j < size-1; j++){
- if( strcmp(pointVet[j],pointVet[j+1]) > 0){
- token = pointVet[j+1];
- pointVet[j+1] = pointVet[j];
- pointVet[j] = token;
- }
- }
- size--;
- }
- }
- void archiveGen (char *pointVet[], int size){
- int i;
- FILE *fp;
- fp = fopen("names_arranged.txt","w");
- for(i = 0; i < size; i++)
- fprintf(fp,"%d %s\n",i+1,pointVet[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment