Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<ctype.h>
  6. typedef struct Row
  7. {
  8. char txt[255];
  9. int no;
  10.  
  11. }Row_t;
  12. int countNO(char *s)
  13. {
  14. // vecinu si curentul ;
  15. int i=0,res=0;
  16. while(s[i])
  17. {
  18. if(isdigit(s[i]))
  19. {
  20. if(i==0||isspace(s[i-1]) || (isspace(s[i+1])))
  21. {
  22. res++;
  23. }
  24. while(isdigit(s[i]))
  25. {
  26. i++;
  27. }
  28. }
  29. if(s[i])
  30. {
  31. i++;
  32. }
  33. }
  34. return res;
  35.  
  36. }
  37. //functia de comparatie
  38. int Rowcmp( const void *r1, const void *r2)
  39. {
  40. Row_t rw1=*(Row_t*)r1;
  41. Row_t rw2=*(Row_t*)r2;
  42. return rw1.no-rw2.no;
  43. }// daca erau stringuri return countNo(rw1)-countNo(rw2);
  44. int main()
  45. {
  46. int norows=0;
  47. char s[255];
  48. Row_t* rows=NULL;
  49. FILE *fin;
  50. fin=fopen("simple.c.txt","r");
  51. if(fin!=NULL)
  52. {
  53. while(fgets(s,255,fin)!=NULL)
  54. {
  55. Row_t* aux=realloc(rows,(norows+1)*sizeof(Row_t));
  56. if(aux!=NULL)
  57. {
  58. rows=aux;
  59. strcpy(rows[norows].txt,s);
  60. rows[norows].no=countNO(s);
  61. norows++;
  62.  
  63. }
  64. else
  65. {
  66. free(rows);
  67. }
  68. }
  69. }
  70. else
  71. printf("erros \n");
  72. qsort(rows,norows,sizeof(Row_t),Rowcmp);
  73. for(int i=0;i<norows;i++)
  74. {
  75. printf("%d %s", rows[i].no,rows[i].txt);
  76. }
  77. return 0;
  78. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement