嵌入式CC++笔试与面试题集(含答案、史上最全)(5)

2019-04-16 16:34

char *addr = dest; int val_len = strlen(src); dest[val_len] = '\\0'; int i;

for (i=0; inext; while(q!=NULL) {

temp=q->next; q->next=p; p=q; q=temp; }

这样增加个辅助的指针就行乐。 ok 通过编译的代码: #include #include #include

typedef struct List{ int data;

struct List *next; }List;

List *list_create(void) {

struct List *head,*tail,*p; int e;

head=(List *)malloc(sizeof(List)); 第 21 页 共 55 页

tail=head;

printf(\ scanf(\ while(e){

p=(List *)malloc(sizeof(List)); p->data=e; tail->next=p; tail=p;

scanf(\ tail->next=NULL; return head; }

List *list_reverse(List *head) {

List *p,*q,*r; p=head; q=p->next; while(q!=NULL) {

r=q->next; q->next=p; p=q; q=r; }

head->next=NULL; head=p;

第 22 页 共 55 页

return head; }

void main(void) {

struct List *head,*p; int d;

head=list_create(); printf(\

for(p=head->next;p;p=p->next) printf(\ head=list_reverse(head); printf(\

for(p=head;p->next;p=p->next) printf(\ }

编写函数数N个BYTE的数据中有多少位是1。

解:此题按步骤解:先定位到某一个BYTE数据;再计算其中有多少个1。叠加得解。 #incluede #define N 10 //定义BYTE类型别名 #ifndef BYTE

typedef unsigned char BYTE; #endif

int comb(BYTE b[],int n) {

int count=0;

第 23 页 共 55 页

int bi,bj; BYTE cc=1,tt;

//历遍到第bi个BYTE数据 for(bi=0;bi>1; tt=tt/2; } }

return count; } //测试 int main() {

BYTE b[10]={3,3,3,11,1,1,1,1,1,1}; cout

1。编写一个 C 函数,该函数在一个字符串中找到可能的最长的子字符串,且该字符串是由同一字符组成的。

char * search(char *cpSource, char ch) {

char *cpTemp=NULL, *cpDest=NULL; int iTemp, iCount=0; while(*cpSource) {

if(*cpSource == ch) {

iTemp = 0;

cpTemp = cpSource;

第 24 页 共 55 页

while(*cpSource == ch) ++iTemp, ++cpSource; if(iTemp > iCount)

iCount = iTemp, cpDest = cpTemp; if(!*cpSource) break; }

++cpSource; }

return cpDest; }

#include #include //

// 自定义函数MyAtoI

// 实现整数字符串转换为证书输出

// 程序不检查字符串的正确性,请用户在调用前检查 //

int MyAtoI(char str[]) { int i;

int weight = 1; // 权重 int rtn = 0; // 用作返回

for(i = strlen(str) - 1; i >= 0; i--) {

rtn += (str - '0')* weight; //

第 25 页 共 55 页


嵌入式CC++笔试与面试题集(含答案、史上最全)(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:隧道工程试题及答案(四套体)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: