main.c

来自「这是一个很简单的在linux环境下的线程编程例子」· C语言 代码 · 共 65 行

C
65
字号
#include <stdio.h>#include "declare.h"int SetData(){   //获取数据源函数	int slt;	int count_length;	char buf[12];	while (1)//当输入的字符不是"0.1.2"时就继续输入	{		GetDataFace();//调用第二函数界面		scanf("%s",buf);//选择功能		slt = atoi(buf); //把字符串转化为整形数		switch(slt)		{		case 0://返回			return 0;		case 1://文件读入			system("clear"); //清屏			count_length=ReadFromFile();//调用			printf("OK!The data already set,press ENTER key to continue:");			getchar(); getchar();			return count_length;		case 2://直接输入			system("clear");//清屏			count_length=InputData(); //调用			printf("OK!The data already set,press ENTER key to continue:");			getchar(); getchar();			return count_length;		}	}}int main(){	int slt;	int n,sum,count_length=0;	char buf[12];	while (1)//当输入的字符不是"0.1.2.3"时就继续输入	{		MainFace();//调用界面函数		scanf("%s",buf);//选择功能		slt = atoi(buf);//把字符串转化为整形数		switch(slt)		{		case 0:       //退出 			return 0;		case 1:      //获取数据源			count_length=SetData(); break;		case 2:     //二线程求和			system("clear");//清屏			printf("The summation of array is: %d\n",arr2sum(count_length)); //调用求和并输出结果			printf("Press ENTER key to continue:"); getchar();getchar();			break;		case 3:    //多线程求和			system("clear");//清屏			printf("Input the number of thread:");			scanf("%s",buf); n=atoi(buf);//输入的线程数			printf("The summation of array is: %d\n",arrnsum(count_length,n)); //调用求和并输出结果			printf("Press ENTER key to continue:"); getchar();getchar();			break;		}	}	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?