?? basic.h
字號:
#ifndef basic_h
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define basic_h
char *errormsg[256];
//process control block
struct pcb
{
int pid; //process id
int ppid; //parent process id
int prio; //priority
int state; //state
int lasttime; //last execute time
int tottime; //totle execute time
};
//process node
struct pnode
{
pcb *node;
pnode *sub;
pnode *brother;
pnode *next;
};
//信號量
struct semphore{
char name[5]; //名稱
int count; //計數值
int curpid; //當前進程id
pnode *wlist; //等待列表
};
#define geterror(eno) printf("%s\n",errormsg[eno])
void initerror()
{
errormsg[0] = (char *)malloc(20);
errormsg[0]="error command!";
errormsg[1] = (char *)malloc(20);
errormsg[1]="error parameter!";
}
//get a substring in string s
char * substr(char *s,int start,int end)
{
char *s1;
int len = strlen(s);
if(start<0 || end>=len || start>end)
return NULL;
s1=(char *)malloc(end-start+2);
for(int i=0;i<=end-start;i++)
s1[i] = s[i+start];
s1[i]='\0';
return s1;
}
//find the location of c in string s
int instr(char *s,char c)
{
int i;
for(i=0;i<strlen(s);i++)
if(s[i]==c)
return i;
return -1;
}
//change the string to array data
int * strtoarray(char *s)
{
int *a,count,i,x1;
char c, *s1,*s2;
if(!s)
{
printf("string can't be null!\n");
return NULL;
}
count=0;
s1=s;
for(i=0;i<strlen(s1);i++)
if(s1[i]==',')
count++;
count++;
a = (int *)malloc(count);
c=',';
for(i=0;i<count;i++)
{
x1 = instr(s1,c);
if(x1>=0)
s2=substr(s1,0,x1-1);
else
s2=s1;
a[i]=atoi(s2);
if(c==',')
s1=substr(s1,x1+1,strlen(s1)-1);
}
return a;
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -