Fourth soft foundation engineering work

git address  https://github.com/npcccc1/WordCount
partner Xu Rui 201 831 061 409
Partner blog  https://www.cnblogs.com/codingbyjusticexu/

 

 

 

 

A, PSP table

 

 Second, code implementation

  And partners chose a different language to get the job done (c and c ++), so use the warehouse to put two different projects. As it is not in a bedroom, their own specific code per person knock. After the test, and adjust the code specifications to further improve after the discussion.

int main () // put the first simple main function
{                                                               
	FILE * fpa;
	FILE *fpb;
	if ((fpa = fopen("D:\\wordCount.txt", "r")) == NULL)
	{
		printf("Failure to open wordCount.txt!\n");
		exit(0);
	}
	if ((fpb = fopen("D:\\Countresult.txt", "w")) == NULL)
	{
		printf("Failure to open wordCount.txt!\n");
		exit(0);
	}
	countchar (fpa, fpb);
	wordcount(fpa,fpb);
	fclose(fpa);
	fclose(fpb);
	return 0;
}

  

  

     void countchar (FILE * a, FILE * b) // statistical character function
	{// ps: I want to become a start number of the outputs a to z alphabet ... 26  
		char c;
		int  d=0;
		int  i=0;
		int p = 0;
		int q = 0;
		while(!feof(a))
		{
			c=fgetc(a);
			if(c>=48&&c<=57)
			{
				d++;
			}	
			else if(c>=65&&c<=90)
			{
				i++;
			}
			else if(c>=97&&c<=122)
			{
				p++;
			}
			else 
			{
				q++;
			}		
		}
		rewind(a);
		fprintf(b,"0--9\t%d\nA--Z\t%d\na--z\t%d\nSeparator\t%d\n",d,i,p,q);
	}

  

  

	void wordcount(FILE *a,FILE *b)
	{
		int  i;
		int q = 0;
		char str[N][N];
		while(!feof(a))
		{
			for(i=0;;i++)
			{
				int p = 0;
				fgets(str[i],N,a);
				
				if((str[i][p]>=97&&str[i][p]<=122)||(str[i][p]>=65&&str[i][p]<=90))
				
				{
					loop: p ++; // normally should not add goto really do not want to reuse the cycle
					
					while((str[i][p]>=97&&str[i][p]<=122)||(str[i][p]>=65&&str[i][p]<=90))
					{
						p++;                         
					}
					if(p>=4)
					{
					if(str[i][p]>=48&&str[i][p]<=57)
						{
						do
							{
								p++;	
							}
							while(str[i][p]>=48&&str[i][p]<=57);
							q++;
							goto loop;
						}
						q++;
					}
									
				}
				
				fprintf(b,"%d\t",q);				
			}	
		} 

	}

Third, the code specification

  After discussion, the specifications are detailed in this link . After reading your own code control discovery did not pay attention before a little bad habits - write a function always empty tabs, resulting in a complex cycle "{}" because this is often the beginning of the Tab and shrink back Jin, appears in front of a large blank, affect the appearance.

  There is a variable name is not standardized, often their own freedom to take.

Fourth, code review

  Not so much a review, in fact, more like the change in writing. Start compiling no problem was very happy, but found no open the file to print out anything. On a four operations also encountered this situation, because the last time && and || have a wrong, leading to a cycle of the card did not export any formula.

   This is a start for the first time passed the code on github, the cycle too much to deal with a string of numbers or other symbols is not the word, let my mind a bit chaotic, at the beginning of this output is also no reason. In addition also small zero error fragmented, but also to be able to check it out yourself Duokanjibian. For efficiency, but also because of different methods used in different languages, did not let fellow peer review.

Fifth, performance analysis

  Do not know why replicate past which said fopen vs potentially unsafe, the compiler does not come out to test it out.

VI Summary and Reflection

  C of process-oriented language with deep feelings, not because of his own subdivision module and multi-function results in an error, inefficiency, there was still divided c ++ module encapsulation and simpler than the c language. But the pair did provide ideas even if we exchange the code is not detailed, often in exchange qq on a number of issues and progress and their own ideas, it can be clearly felt that 1 + 1> 2,

 

Guess you like

Origin www.cnblogs.com/npc1158947015/p/11681310.html