| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 591 人关注过本帖
标题:[求助]如何将字符串复制到二维数组里
只看楼主 加入收藏
gonua
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-16
收藏
 问题点数:0 回复次数:1 
[求助]如何将字符串复制到二维数组里


请大家帮忙看看, 就是把最新选择的菜单选项的function的输出部分显示在第3个function里面。。。。
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#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不会。。。。
}

谢谢~~

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

搜索更多相关主题的帖子: 字符 
2007-08-26 08:53
gonua
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-16
收藏
得分:0 
没人可以帮我吗?
谁能给我个思路??拜托~~~~

2007-08-26 20:34
快速回复:[求助]如何将字符串复制到二维数组里
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011669 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved