c语言程序设计题...

来源:百度知道 编辑:UC知道 时间:2024/05/16 05:59:58
首先说下...是unix系统的..(虽然我不了解有没关系- -||)
./a.out是运行指令
1,做可以返回文字列长度的str_length函数。实行时如下
./a.out apple orange lemon
apple:5
orange:6
lemon:5
2,实行如下
./a.out 123.45
123.45=123+0.450000
3,定义一个函数,可以计算如下格式
《16进正整数》《运算符》《16进正整数》
例如 2f+b
实行如下 ./a.out 2f+b
非常感谢二楼的大虾!!我想问下,第一题,用另外定义的str_length计算文字列长度,不是直接用strlen
第二题,如果实行时还有两个数怎么办?比方说123.45,67.89,10.20
非常感谢!!

1.
#include "stdio.h"
int main(int n,char **s){
int i;
for(i=1;i<n;i++){

printf("%s:%d\n",s[i],strlen(s[i]));

}
return 0;
}
2.
#include "stdio.h"
#include "string.h"
int main(int argv,char** str){
int i=0;
float f;

int n,t=0;

float f2=0,temp=0;

int flag=1;

while(flag==1){

if(str[1][i]=='.'){

flag=0;

}

else if(str[1][i]=='\0'){

flag=-1;

}

else {

t=t*10+(str[1][i]-'0');

}

i++;

}

n=t;

float st=0.1;

if(flag==0){

while(str[1][i]){

temp=temp+(str[1][i]-'0')*st;

st/=10;

i++;

}

f2=temp;

}

pr