Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<ctype.h>
- typedef struct Row
- {
- char txt[255];
- int no;
- }Row_t;
- int countNO(char *s)
- {
- // vecinu si curentul ;
- int i=0,res=0;
- while(s[i])
- {
- if(isdigit(s[i]))
- {
- if(i==0||isspace(s[i-1]) || (isspace(s[i+1])))
- {
- res++;
- }
- while(isdigit(s[i]))
- {
- i++;
- }
- }
- if(s[i])
- {
- i++;
- }
- }
- return res;
- }
- //functia de comparatie
- int Rowcmp( const void *r1, const void *r2)
- {
- Row_t rw1=*(Row_t*)r1;
- Row_t rw2=*(Row_t*)r2;
- return rw1.no-rw2.no;
- }// daca erau stringuri return countNo(rw1)-countNo(rw2);
- int main()
- {
- int norows=0;
- char s[255];
- Row_t* rows=NULL;
- FILE *fin;
- fin=fopen("simple.c.txt","r");
- if(fin!=NULL)
- {
- while(fgets(s,255,fin)!=NULL)
- {
- Row_t* aux=realloc(rows,(norows+1)*sizeof(Row_t));
- if(aux!=NULL)
- {
- rows=aux;
- strcpy(rows[norows].txt,s);
- rows[norows].no=countNO(s);
- norows++;
- }
- else
- {
- free(rows);
- }
- }
- }
- else
- printf("erros \n");
- qsort(rows,norows,sizeof(Row_t),Rowcmp);
- for(int i=0;i<norows;i++)
- {
- printf("%d %s", rows[i].no,rows[i].txt);
- }
- return 0;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement