将字符串分割成二维数组c语言,[求助]如何将字符串复制到二维数组里

[求助]如何将字符串复制到二维数组里

请大家帮忙看看, 就是把最新选择的菜单选项的function的输出部分显示在第3个function里面。。。。

cea4dedea1354b89f59029cae6049909.gif

1) Interest Calculator

2) sort line

3) summary

4) exit

--------------------------------

enter option: 2

enter a string: qwe234

new string is: ewq

--------------------------------

enter option: 1

enter amount: 100

enter year: 2

Investment is: 132.25

--------------------------------

enter option: 3 //这个function不知道怎么做,还请大家帮帮我 。。。。

1) new string is: ewq

2) Investment is: 132.25

如果先选1再选2,就显示:

1)Investment is: 132.25

2) new string is: ewq

code:

#include

#include

#include

#include

#define OUTPUT_LEN 80

#define OUTPUT_MAX 2

#define INTEREST_RATE 15

#define PERCENT 0.01

#define STRLEN 40

#define ONE 1

void initOutputs(char[OUTPUT_MAX][OUTPUT_LEN]);

void interestCalculator(char[OUTPUT_MAX][OUTPUT_LEN]);

void sortLine(char[OUTPUT_MAX][OUTPUT_LEN]);

void summary(char[OUTPUT_MAX][OUTPUT_LEN]);

void readRestOfLine();

int main(void)

{

char lastOutputs[OUTPUT_MAX][OUTPUT_LEN];

char choice;

int done = 0;

initOutputs(lastOutputs);

while(!done)

{

printf("\nMenu:");

printf("\n1) Interest Calculator");

printf("\n2) Sort line");

printf("\n3) Session Summary");

printf("\n4) Exit");

printf("\nEnter option: ");

choice = getchar();

switch(choice)

{

case '1':

interestCalculator(lastOutputs);

break;

case '2':

sortLine(lastOutputs);

break;

case '3':

summary(lastOutputs);

break;

case '4':

exit(0);

break;

default :

break;

}

}

return EXIT_SUCCESS;

}

//这个function是题里本来就有的

void initOutputs(char lastOutputs[OUTPUT_MAX][OUTPUT_LEN])

{

int i;

for (i = 0; i < OUTPUT_MAX; i++)

{

strcpy(lastOutputs[i], "");

}

}

void interestCalculator(char lastOutputs[OUTPUT_MAX][OUTPUT_LEN])//这里只有一个参数也是固定的

{

int investmentAmount, year;

double fixRate, rate, newInvestment;

char string[70] = "Your investment grows to: ";

char str;

printf("1) Interest Calculator\n");

printf("----------------------\n");

printf("Enter amount: ");

scanf("%d", &investmentAmount);

printf("\nEnter year: ");

scanf("%d", &year);

fixRate = (double)(ONE + (INTEREST_RATE*PERCENT));

rate = (double)pow(fixRate, year);

newInvestment = investmentAmount * rate;

printf("\nInvestment is: $%.2lf", newInvestment);

}

void sortLine(char lastOutputs[OUTPUT_MAX][OUTPUT_LEN])

{

char str[STRLEN],str1[STRLEN];

int i, j, k, n, temp, length;

printf("\n2) Sort Line");

printf("\n------------\n");

printf("\nEnter a string: ");

scanf("%s", str);

length = strlen(str);

if(length < STRLEN)

{

for(i = 0; i < length; i++)

{

for(j = i+1; j < length; j++)

{

if(str[i] > str[j])

{

temp = str[i];

str[i] = str[j];

str[j] = temp;

}

}

}

for(n = 0,k = 0; k < length; k++)

{

if(isalpha((int)str[k]))

{

str[k] = tolower(str[k]);

str1[n++] = str[k];

str1[n]='\0';

}

}

printf("\nnew string is: %s", str1);

}

}

void summary(char lastOutputs[OUTPUT_MAX][OUTPUT_LEN])

{

//这个function不会

cea4dedea1354b89f59029cae6049909.gif。。。。

}

谢谢~~

13a2f4bd84d8af35e7645442bb7a26a3.gif

[此贴子已经被作者于2007-8-26 8:58:35编辑过]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值