linux驱动程序是什么,简述一个Linux驱动程序的主要流程与功能
1.?簡(jiǎn)述一個(gè)Linux驅(qū)動(dòng)程序的主要流程與功能。
2.?請(qǐng)列舉一個(gè)軟件中時(shí)間換空間或者空間換時(shí)間的例子。
void swap(int a,int b)
{
int c; c=a;a=b;b=a;
}
--->空優(yōu)
void swap(int a,int b)
{
a=a+b;b=a-b;a=a-b;
}
6.?請(qǐng)問一下程序?qū)⑤敵鍪裁唇Y(jié)果?
char *RetMenory(void)
{
char p[] = “hellow world”;
return p;
}
void Test(void)
{
char *str = NULL;
str = RetMemory();
printf(str);
}
RetMenory執(zhí)行完畢,p資源被回收,指向未知地址。返回地址,str的內(nèi)容應(yīng)是不可預(yù)測(cè)的,
打印的應(yīng)該是str的地址
寫一個(gè)函數(shù),它的原形是int continumax(char *outputstr,char
*intputstr)
功能:
在字符串中找出連續(xù)最長(zhǎng)的數(shù)字串,并把這個(gè)串的長(zhǎng)度返回,并把這個(gè)最長(zhǎng)數(shù)字串付給其中一個(gè)函數(shù)參數(shù)outputstr所指內(nèi)存。例如:"abcd12345ed125ss123456789"的首地址傳給intputstr后,函數(shù)將返回
9,outputstr所指的值為123456789
int continumax(char *outputstr, char *inputstr)
{
char *in = inputstr, *out = outputstr, *temp, *final;
int count = 0, maxlen = 0;
while( *in != \'\\0\' )
{
if( *in > 47 && *in < 58 )
{
for(temp = in; *in > 47 && *in < 58 ; in++ )
count++;
}
else
in++;
if( maxlen < count )
{
maxlen = count;
count = 0;
final = temp;
}
}
for(int i = 0; i < maxlen; i++)
{
*out = *final;
out++;
final++;
}
*out = \'\\0\';
return maxlen;
}
不用庫(kù)函數(shù),用C語(yǔ)言實(shí)現(xiàn)將一整型數(shù)字轉(zhuǎn)化為字符串
方法1:
int getlen(char *s){
int
n;
for(n =
0; *s != \'\\0\'; s++)
n++;
return
n;
}
void reverse(char s[])
{
int c,i,j;
for(i = 0,j = getlen(s) -
1; i < j; i++,j--){
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
void itoa(int n,char s[])
{
int i,sign;
if((sign = n) < 0)
n = -n;
i = 0;
do{/*以反序生成數(shù)字*/
s[i++] = n%10 + \'0\';/*get next number*/
}while((n /= 10) >
0);/*delete the number*/
if(sign < 0)
s[i++] = \'-\';
s[i] = \'\\0\';
reverse(s);
}
方法2:
#include
using namespace std;
void itochar(int num);
void itochar(int num)
{
int i = 0;
int j ;
char stra[10];
char strb[10];
while ( num )
{
stra[i++]=num%10+48;
num=num/10;
}
stra[i] = \'\\0\';
for( j=0; j < i; j++)
{
strb[j] = stra[i-j-1];
}
strb[j] = \'\\0\';
cout<
}
int main()
{
int num;
cin>>num;
itochar(num);
return 0;
}
前幾天面試,有一題想不明白,請(qǐng)教大家!
typedef struct
{
int a:2;
int b:2;
int c:1;
}test;
test t;
t.a = 1;
t.b = 3;
t.c = 1;
printf("%d",t.a);
printf("%d",t.b);
printf("%d",t.c);
謝謝!
t.a為01,輸出就是1
t.b為11,輸出就是-1
t.c為1,輸出也是-1
3個(gè)都是有符號(hào)數(shù)int嘛。
這是位擴(kuò)展問題
01
11
1
編譯器進(jìn)行符號(hào)擴(kuò)展
求組合數(shù): 求n個(gè)數(shù)(1....n)中k個(gè)數(shù)的組合....
如:combination(5,3)
要求輸出:543,542,541,532,531,521,432,431,421,321,
#include
int pop(int *);
int push(int );
void combination(int ,int );
int stack[3]={0};
top=-1;
int main()
{
int n,m;
printf("Input two numbers:\\n");
while( (2!=scanf("%d%*c%d",&n,&m)) )
{
fflush(stdin);
printf("Input error! Again:\\n");
}
combination(n,m);
printf("\\n");
}
void combination(int m,int n)
{
int temp=m;
push(temp);
while(1)
{
if(1==temp)
{
if(pop(&temp)&&stack[0]==n)
//當(dāng)棧底元素彈出&&為可能取的最小值,循環(huán)退出
break;
}
else if( push(--temp))
{
printf("%d%d%d?",stack[0],stack[1],stack[2]);//§?¨ì¤@?
pop(&temp);
}
}
}
int push(int i)
{
stack[++top]=i;
if(top<2)
return 0;
else
return 1;
}
int pop(int *i)
{
*i=stack[top--];
if(top>=0)
return 0;
else
return 1;
}
1、用指針的方法,將字符串“ABCD1234efgh”前后對(duì)調(diào)顯示
#include
#include
#include
int main()
{
char
str[] = "ABCD1234efgh";
int
length = strlen(str);
char * p1
= str;
char * p2
= str + length - 1;
while(p1
< p2)
{
char c = *p1;
*p1 = *p2;
*p2 = c;
++p1;
--p2;
}
printf("str now is %s\\n",str);
system("pause");
return
0;
}
2、有一分?jǐn)?shù)序列:1/2,1/4,1/6,1/8……,用函數(shù)調(diào)用的方法,求此數(shù)列前20項(xiàng)的和
#include
double getValue()
{
double
result = 0;
int i =
2;
while(i
< 42)
{
result += 1.0 /
i;//一定要使用1.0做除數(shù),不能用1,否則結(jié)果將自動(dòng)轉(zhuǎn)化成整數(shù),即0.000000
i += 2;
}
return
result;
}
int main()
{
printf("result is %f\\n", getValue());
system("pause");
return
0;
}
有一個(gè)數(shù)組a[1000]存放0--1000;要求每隔二個(gè)數(shù)刪掉一個(gè)數(shù),到末尾時(shí)循環(huán)至開頭繼續(xù)進(jìn)行,求最后一個(gè)被刪掉的數(shù)的原始下標(biāo)位置。
以7個(gè)數(shù)為例:
{0,1,2,3,4,5,6,7}
0-->1-->2(刪除)-->3-->4-->5(刪除)-->6-->7-->0(刪除),如此循環(huán)直到最后一個(gè)數(shù)被刪除。
方法1:數(shù)組
#include
using namespace std;
#define null 1000
int main()
{
int arr[1000];
for (int i=0;i<1000;++i)
arr[i]=i;
int j=0;
int count=0;
while(count<999)
{
while(arr[j%1000]==null)
j=(++j)%1000;
j=(++j)%1000;
while(arr[j%1000]==null)
j=(++j)%1000;
j=(++j)%1000;
while(arr[j%1000]==null)
j=(++j)%1000;
arr[j]=null;
++count;
}
while(arr[j]==null)
j=(++j)%1000;
cout<
return 0;
}方法2:鏈表
#include
using namespace std;
#define null 0
struct node
{
int data;
node* next;
};
int main()
{
node* head=new node;
head->data=0;
head->next=null;
node* p=head;
for(int i=1;i<1000;i++)
{
node* tmp=new node;
tmp->data=i;
tmp->next=null;
head->next=tmp;
head=head->next;
}
head->next=p;
while(p!=p->next)
{
p->next->next=p->next->next->next;
p=p->next->next;
}
cout<data;
return 0;
}
總結(jié)
以上是生活随笔為你收集整理的linux驱动程序是什么,简述一个Linux驱动程序的主要流程与功能的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux怎么调整运行模式,如何手动设置
- 下一篇: tl-wn821n无线网卡驱动 linu