السلام عليكم ..
عندي مشكلة في assignment .. حليته .. بس عندي أخطاء ومو عارفة أصححها
إذا ممكن أحد يساعدني ضروووووووووووووري
..
هذا هو حلي ..
عرض الكل
الجزء الثالث من السؤال ما فهمته عدل .. بس حاولت فيه .. و إن شاء تقدرون تساعدوني ..
عااااااجل جداً الله يخليكم ..

وهذا هو السؤال ..
عندي مشكلة في assignment .. حليته .. بس عندي أخطاء ومو عارفة أصححها
إذا ممكن أحد يساعدني ضروووووووووووووري
.. هذا هو حلي ..
كود المصدر
- #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");
- else
- {
- 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);
- while(choice>0 && choice<4)
- switch(choice)
- {
- case 1: CountWords(fptr);
- break;
- case 2: findOccuence(fptr);
- break;
- case 3:replaceString(fptr);
- break;
- }
- 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);
- }
- 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[i]," ");
- 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);
- }
- }
الجزء الثالث من السؤال ما فهمته عدل .. بس حاولت فيه .. و إن شاء تقدرون تساعدوني ..
عااااااجل جداً الله يخليكم ..

وهذا هو السؤال ..