مساعدة عااااااااااجلة

    • مساعدة عااااااااااجلة

      السلام عليكم ..

      عندي مشكلة في assignment .. حليته .. بس عندي أخطاء ومو عارفة أصححها :confused:

      إذا ممكن أحد يساعدني ضروووووووووووووري $ $ ..

      هذا هو حلي ..

      كود المصدر

      1. #include<stdio.h>
      2. #include<string.h>
      3. void CountWords(FILE*fptr);
      4. void findOccuence(FILE*fptr);
      5. void replaceString(FILE*fptr);
      6. int main()
      7. {
      8. int choice;
      9. FILE*fptr;
      10. fptr=fopen("text.dat","r");
      11. if (fptr==NULL)
      12. printf("ERROR!! THE FILE CAN NOT BE OPEND!\n");
      13. else
      14. {
      15. printf("\nEnter your choice\n1\t To Count Words In Each Lines.\n2\tTo Find The Number OF The String Occurred In Each Lines.\n3\t To Replace Strings.\n");
      16. scanf("%d",&choice);
      17. while(choice>0 && choice<4)
      18. switch(choice)
      19. {
      20. case 1: CountWords(fptr);
      21. break;
      22. case 2: findOccuence(fptr);
      23. break;
      24. case 3:replaceString(fptr);
      25. break;
      26. }
      27. printf("\nEnter your choice\n1\t To Count Words In Each Lines.\n2\tTo Find The Number OF The String Occurred In Each Lines.\n3\t To Replace Strings.\n");
      28. scanf("%d",&choice);
      29. }
      30. fclose(fptr);
      31. return 0;
      32. }
      33. void CountWords(FILE*fptr)
      34. {
      35. rewind(fptr);
      36. char line[60];
      37. fgets(line,60,fptr);
      38. while(!feof(fptr))
      39. {
      40. char a[20];
      41. int count=0;
      42. int countLines=0;
      43. char*ptr=strtok(line,".");
      44. while(ptr!=NULL)
      45. {
      46. a[countLines]=ptr;
      47. ptr=strtok(NULL,".");
      48. countLines++;
      49. } // end while
      50. printf("Sentences Length:\n");
      51. for(int i=0;i<countLines;i++)
      52. {
      53. char*token=strtok(a[i]," ");
      54. while(token!=NULL)
      55. {
      56. count++;
      57. token=strtok(NULL," ");
      58. } // end while
      59. printf("\t\t Sentence%d:%words",i+1,count);
      60. fgets(line,60,fptr);
      61. count=0;
      62. } // end for
      63. }// end outer while
      64. }
      65. void findOccuence (FILE*fptr)
      66. {
      67. rewind(fptr);
      68. char line [60];
      69. fgets(line,60,fptr);
      70. while(!feof(fptr))
      71. {
      72. int count=0;
      73. int countLines=0;
      74. char*ptr=strstr(line,"string");
      75. while(ptr!=NULL)
      76. {
      77. count++;
      78. countLines++;
      79. ptr=strstr(ptr+1,"string");
      80. } // end inner while
      81. printf("%d\t%d\n",countLines,count);
      82. fgets(line,60,fptr);
      83. } // end outer while
      84. }
      85. void replaceString(FILE*fptr)
      86. {
      87. rewind (fptr);
      88. FILE*fptr2;
      89. char line[60];
      90. char string1=" "; string2=" ";
      91. fgets(line,60,fptr);
      92. while(!feof(fptr))
      93. {
      94. char*token=strtok(line," ");
      95. while(token!=NULL)
      96. {
      97. if(strlen(token)==strstr(line,string1));
      98. strcat(line,string2);
      99. char*token=strtok(line," ");
      100. }
      101. fputs(line,fptr2);
      102. }
      103. }
      عرض الكل


      الجزء الثالث من السؤال ما فهمته عدل .. بس حاولت فيه .. و إن شاء تقدرون تساعدوني ..

      عااااااجل جداً الله يخليكم .. $ $

      وهذا هو السؤال ..
    • #include<stdio.h>
      #include<string.h>

      void CountWords(FILE*fptr);
      void findOccuence(FILE*fptr);
      void replaceString(FILE*fptr);

      int main()
      {
      int choice;
      FILE*fptr;

      fptr=fopen("text.dat","r");
      if (fptr==NULL)
      {
      printf("ERROR!! THE FILE CAN NOT BE OPEND!\n");
      exit(0);
      }

      do
      {
      printf("1.CountWords");
      printf("2.findOccuence");
      printf("3. ");
      printf("4.replaceString");

      printf("\nEnter your choice\n1\t To Count Words In Each Lines.\n2\tTo Find The Number OF The String Occurred In Each Lines.\n3\t To Replace Strings.\n");
      scanf("%d",&choice);

      switch(choice)
      {
      case 1: CountWords(fptr);
      break;

      case 2: findOccuence(fptr);
      break;

      case 3:replaceString(fptr);
      break;
      case 4:exit(1);
      }
      }while(choice>0 && choice<4);

      fclose(fptr);

      return 0;
      }
      void CountWords(FILE*fptr)
      {
      rewind(fptr);
      char line[60];
      fgets(line,60,fptr);

      while(!feof(fptr))
      {
      char a[20];
      int count=0;
      int countLines=0;

      char*ptr=strtok(line,".");

      while(ptr!=NULL)
      {
      a[countLines]=ptr;
      ptr=strtok(NULL,".");
      countLines++;
      } // end while

      printf("Sentences Length:\n");

      for(int i=0;i<countLines;i++)
      {
      char*token=strtok(a," ");
      while(token!=NULL)
      {
      count++;
      token=strtok(NULL," ");
      } // end while
      printf("\t\t Sentence%d:%words",i+1,count);
      fgets(line,60,fptr);

      count=0;
      } // end for
      }// end outer while
      }

      void findOccuence (FILE*fptr)
      {
      rewind(fptr);
      char line [60];
      fgets(line,60,fptr);

      while(!feof(fptr))
      {
      int count=0;
      int countLines=0;
      char*ptr=strstr(line,"string");

      while(ptr!=NULL)
      {
      count++;
      countLines++;
      ptr=strstr(ptr+1,"string");
      } // end inner while

      printf("%d\t%d\n",countLines,count);
      fgets(line,60,fptr);
      } // end outer while

      }

      void replaceString(FILE*fptr)
      {
      rewind (fptr);
      FILE*fptr2;
      char line[60];
      char string1=" "; string2=" ";

      fgets(line,60,fptr);
      while(!feof(fptr))
      {
      char*token=strtok(line," ");
      while(token!=NULL)
      {
      if(strlen(token)==strstr(line,string1));
      strcat(line,string2);
      char*token=strtok(line," ");
      }

      fputs(line,fptr2);

      }

      }