Why write a WeChat public account? During the process of learning C language, I found that most resources online are just selling courses. Some platforms automatically convert you to VIP articles to sell their memberships, and on Douyin, there are videos with the suffix HTML claiming to be Python projects, with comments just dragging on like “111“. It’s better to find me for some free resources.
Of course, there are also well-written articles, but they are quite scattered, so one has to rely on patience to find them. Thus, I decided to write a public account to share some insights.
I used to follow a public account that shared source code for free, but recently they have started to use private messages to share code. Although I have been a long-time follower, I can still get resources for free. It seems that the path to obtaining resources is getting wider, yet also narrower.
I asked him: Brother, why haven’t you continued to share source code recently? You used to post it.
A: Do you want it? I can send it to you since I see you’ve been following me for a while.
I: No need, I just want to learn. You used to share the source code at the end of your articles, what happened now?
A: I don’t want to share anymore; it’s all free riders. I can only say it’s hard to persist. Many people just copy and paste without even liking or commenting. You see others are benefiting, and can those organizations still ask you to advertise?
I: Then why did you start writing a public account in the first place?
A: Back then, it was really hard to find resources, purely for sharing. But now, finding resources is easy, but distinguishing good resources is difficult. So pure sharing is hard to maintain; the mindset has changed. You’ve been watching me for so long; you can try it too.
Alright, I’ll give it a try. How long can I persist? It’s hard to say.
I mainly want to share some random things. It’s not that profound; my learning ability isn’t great, and I haven’t fully digested what I learned in college. I’m not as good as those who took classes. Still, I believe in pure sharing; if I find something worth saving, I’ll share it.
A senior who has graduated said that during four years of college, he didn’t know what he learned. If it were me, I’d rather have taken classes directly for four years. In this market, who says that those from training classes aren’t considered professionals?
Professionals probably can’t code as well as someone from a three-month training class.
There’s no noticeable difference between professionals and those from training classes in actual work; both just use Ctrl+C Ctrl+V. Those from unconventional backgrounds might even be stronger. Professionals have a better foundation.
Enough said, today I’ll share the use of pointer arrays for the first time.
A number guessing game that uses pointer arrays to allow the user to choose the difficulty level.
#include<stdio.h>#include<stdlib.h>#include<time.h>void Menu();int range_num1();int range_num2();int range_num3();int range_num4();int main(){ Menu(); int choose; scanf("%d",&choose); int(*arr[4])() = {range_num1,range_num2,range_num3,range_num4}; int number = arr[choose -1](); int count = 0; int guess_number; do { count++; printf("请输入你猜测的数字:\n"); scanf("%d",&guess_number); if(guess_number<number) { printf("你猜小了请再猜一次;\n"); } else if(guess_number>number) { printf("你猜大了,请再猜一次;\n"); } }while(number!=guess_number); printf("恭喜你猜对了,你一共猜了%d次.\n",count); return 0;} void Menu(){ printf("-------------Menu------------\n"); printf("猜数字小游戏,请选择难度:\n1,简单(1-10),2,普通(1-100),3,困难(1-1000),4,地狱(1-1000)\n");} int range_num1(){ srand(time(NULL)); int num = rand()%10 +1; return num;} int range_num2(){ srand(time(NULL)); int num = rand()%100+1; return num;} int range_num3(){ srand(time(NULL)); int num =rand()%1000+1; return num;} int range_num4(){ srand(time(NULL)); int num = rand()%10000+1;}
A small calculator that also uses pointer arrays, but can only output floating-point numbers.
#include<stdio.h>//利用函数指针实现简单计算器double Add(double num1,double num2);double Sub(double num1,double num2);double Mult(double num1,double num2);double Divi(double num1,double num2);void Menu();int main(){ Menu(); double num1,num2; scanf("%lf %lf",&num1,&num2); printf("请输入需要进行的计算[1][2][3][4]:"); int attmpt; scanf("%d",&attmpt); double(*arr[4])(double,double) = {Add,Sub,Mult,Divi}; double res = arr[attmpt-1](num1,num2); printf("结果是%.2lf\n",res); return 0;}//定义加法double Add(double num1,double num2){ return num1 + num2;}//定义减法double Sub(double num1,double num2){ return num1 - num2;}//定义乘法double Mult(double num1,double num2){ return num1 * num2;}//定义除法double Divi(double num1,double num2){ //被除数不能为0 if(num2 != 0) { return num1 / num2; } return -1; }void Menu(){ printf("-------------Menu-------------\n"); printf("1,加法\n2,减法\n3,乘法\n4,除法\n结果均保留两位小数\n"); printf("请输入需要计算的两位数:\n");}
Purely hand-coded, without any AI additives. Nowadays, with all the noise about AI, if I share something, the comments say it’s AI. There’s not that much AI. If we’re talking about AI, then I’m also writing with a hint of AI flavor, but it’s strong, no need to say more.