C senior fourth assignment

homework requirement one

Simplest wordcount

Specific requirements: http://www.cnblogs.com/xinz/p/7426280.html

1. Design ideas:

Design ideas for version 0.0:

Step 1: Read the file name that the user wants to operate
Step 2: Find and open the file
Step 3: If statement matches the relevant function
Step 4: Implement the relevant function and return the result
Step 5: Close the file

Version 1.0 Design Ideas

I got related inspiration from the PHP project I recently learned, and each function can be encapsulated into a function to implement related functions, which is more conducive to structured coding

Version 2.0 Design Ideas

Implement related advanced functions

2. Main code

Relevant code for version 0.0

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    char name[20];//用来存需要操作的文件的文件名
    char function[2];//用来匹配对相关文件需要进行的操作
    int charNum=0,wordNum=0,lineNum=0;//分别用来统计字符数、词数和行数

    //读入文件名
    printf("请输入需要进行操作文件的文件名:");
    scanf("%s",&name);

    //定义文件指针
    FILE *fp;

    //打开文件
    if(( fp = fopen( name, "r" )) == NULL){
            printf(" File open error!\n" );
            exit(0);
    }

    //读入想要对文件进行的相关操作
    printf("请输入需要对文件进行的相关操作\n -c统计文件中的字符数\n -w统计文件中的词数\n -l统计文件的行数\n");
    scanf("%s",&function);

    //匹配读入的功能并操作文件

    //统计文件字符数
    if((function[0]=='-')&&(function[1]=='c')){
        char ch;
        ch = fgetc(fp);//fgetc(文件名)函数从指定文件中读取一个字符EOF用来检测是否到文件的末尾
        while(ch!=EOF){
            charNum++;
            ch = fgetc(fp);
        }
        charNum--;
        printf("文件中的字符数为:%d",charNum);
    }

    //统计文件词数
    if((function[0]=='-')&&(function[1]=='w')){
        char ch;
        while(feof(fp)==0){
                fscanf(fp,"%s",&ch);
                wordNum++;
        }
        wordNum--;
        printf("文件中的词数为:%d",wordNum);

    }

    //统计文件行数
    if((function[0]=='-')&&(function[1]=='l')){
            char ch;
            ch = fgetc(fp);
            while(ch!=EOF){
                if(ch=='\n'){
                    wordNum++;
                }
                ch = fgetc(fp);
            }
            printf("文件中的行数为:%d",wordNum);
    }


    //关闭文件
    if(fclose(fp)){
            printf("Can not close the file!\n");
            exit(0);
    }

    return 0;
}

3. Related problems encountered and solutions

multi-character constant constant exception warning
Error analysis: When writing the function for the first time, it is a string. When using if to match, it will report a multi-character constant constant exception.
Solution: Write the function as a character array and compare whether the two characters match the
1.0 and 2.0 version codes. renew

Summary of learning progress:

1. My Github address: https://github.com/XINJY/The-homework-of-C

Screenshots of successful uploads: The upload is always unsuccessful today, it may be a network problem. After the upload is successful, come back and make up the screenshots

2. Students who commented

3. Charts and Line Charts

4. The course of this semester is coming to an end. Please summarize your achievements in this course and review the 0th assignment. Have you achieved your goal?

Gains from this course: I won’t list the professional knowledge level, let’s talk about blog assignments. I remember when the course first started, I didn’t know what blog assignments were at that time, let alone how to write so-called blog assignments. Blog assignments. Now I can fluently write down my own problem-solving ideas, skillfully use ProcessOn to draw qualified flowcharts, and learn to simply use the Github that I have only heard of before, and I can skillfully use the simple syntax of Markdown. The typesetting of one's own blog, the ability to seriously investigate where an error is reported, how to describe the error, and how to correct it, these are the gains brought by blogging.
The 0th homework: http://www.cnblogs.com/X-JY/p/8516188.html
Looking back at the 0th homework again, it seems that the high-spirited self was yesterday, and 9 weeks have passed before you know it. This may be my last C class, but my C learning journey will never stop there.
Ok, back to the topic, let's start to review the realization of my 0th homework goal: the ideal is always much richer than the reality, the so-called books have not been opened at all, and the so-called exercise programs have not been found at all, Although I force myself to study hard, there are still times when my mind wanders in class. In general, the goals at that time were also achieved and not achieved. I believe that I will do better in the days to come, and I will always owe the world a better self.

5. Do you have any comments and suggestions on the current class and homework method (class explanation + PTA + blog)?

6. Finally, we will no longer be teachers and students. When you finish this course, you and I are in the same position, and I will no longer have any interference with your freedom based on school mandates and advantages in knowledge, experience (age?). One last time I exercised teacher privileges other than posting grades: do you have anything to say to the teacher (me), suggestions, complaints, hopes...Thanks a lot.

In order to avoid the repetition of suggestions, I put 5 and 6 together (of course, it is more because I am lazy). First of all, I would like to thank the teachers for their hard work after a semester. I know that it is very time-consuming for us to write a copy of each assignment. It is also time-consuming for teachers to comment and correct more than 70 copies. But at this last moment, I still want to complain that "blog assignments are really hard to write!!!". It is suggested that the teacher first learn about the relevant situation when teaching students of the same type as us next time. We have a lot of classes and various activities (although these cannot be used as a reason for us not to do homework). After all, our energy is limited, and we want to use it. It is sometimes really difficult to complete all the tasks in a timely and high-quality manner with limited energy. Sometimes I am also a little tired of our current form. It is obvious that I can finish writing a topic in ten minutes, but I spend more than half an hour or even an hour to write a blog about this topic. The homework questions left are not a single topic. I think the homework does not require a lot of quantity but requires finesse. For example, we can only ask everyone to carefully pick one topic after each class, and learn and consolidate knowledge from one topic. Questions can be used as optional questions without rigid requirements. If you think you are not good enough, you can also use optional questions to consolidate and learn. Complaining is complaining. Finally, we have to express our heartfelt thanks to our teacher Niu.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325354874&siteId=291194637