家「路由器的摆放位置」的位置摆放对了吗

18:36 提问
新手求教,关于传递字符串数组的问题
以下是我写的c primer plus 第11章习题10的程序,问题是我输入字符串后,用1以外的方式排序,就无法恢复原序列了。也就是每次调用函数都改变了原本数组的顺序,我实在找不到问题出在哪。特请高手指教,如果我的代码还有其他的什么毛病也请指出来。O(∩_∩)O谢谢
#include&stdio.h&
#include&string.h&
#include&ctype.h&
#define LIM 10
#define MAX 81
// 显示菜单函数
void display(void)
puts("******************************************");
puts("1)Print original string");
puts("2)Print in order of ASCII");
puts("3)Print in order of string's length");
puts("4)Print in order of first word's length");
puts("5)quit");
puts("******************************************");
// 判断字符串中第一个单词长度
int w_l(const char *s)
while(isspace(*s))
// 跳过空白字符
// 遇到空字符就退出循环
if(!isspace(*s))
// 原样打印字符串
void opt1(char *msg[], int n)
for(i = 0; i&n; i++)
puts(msg[i]);
// 按ASCII码顺序打印字符串
void opt2(char *msg[], int n)
for(i = 0; i&n-1 ; i++)
for(j = i+1; j&n; j++)
if(strcmp(msg[i], msg[j]) & 0)
temp = msg[i];
msg[i] = msg[j];
for(i = 0; i&n; i++)
puts(msg[i]);
// 按字符串长度打印
void opt3(char *msg[], int n)
for(i = 0; i&n-1 ; i++)
for(j = i+1; j&n; j++)
if(strlen(msg[i]) & strlen(msg[j]))
temp = msg[i];
msg[i] = msg[j];
for(i = 0; i&n; i++)
puts(msg[i]);
// 按第一个单词长度打印
void opt4(char *msg[], int n)
for(i = 0; i&n-1 ; i++)
for(j = i+1; j&n; j++)
if(w_l(msg[i]) & w_l(msg[j]) )
temp = msg[i];
msg[i] = msg[j];
for(i = 0; i&n; i++)
puts(msg[i]);
// 调用驱动函数
int main(void)
char msg[LIM][MAX];
char *ptstr[LIM];
puts("Input strings:");
for(i = 0; i & LIM && gets(msg[i]) != NULL; i++)
// 将字符串存入数组
ptstr[i] = msg[i];
display();
while(scanf("%d", &choice) == 1 && choice != 5)
// 菜单选择
switch(choice)
case 1: opt1(ptstr, i);
case 2: opt2(ptstr, i);
case 3: opt3(ptstr, i);
case 4: opt4(ptstr, i);
display();
puts("Bye.");
按赞数排序
你改写了原数组,你在方法内部声明一个临时数组,来排序,不要改写原有的
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!
其他相似问题20870人阅读
正确的解法:String mess = getResources().getString(R.string.mess_1);另外一种:you can simplify that to&this.getString(R.string.some_id)&
关键点android 字符串比较,android 截取字符串,android 字符串,android 字符串数组,androidpost字符串,android 字符串转换,
字符串资源的定义
文件路径:res/values/strings.xml
字符串资源定义示例:
&?xml&version=&1.0&&encoding=&utf-8&?&
&resources&
&&&&&string&name=&hello&&Hello!&/string&
&/resources&
字符串资源的调用
在 Layout XML 调用字符串资源:
&&&&android:layout_width=&fill_parent&
&&&&android:layout_height=&wrap_content&
&&&&android:text=&@string/hello&&/&
在 Activity 获取字符串资源:
this.getString(R.string.hello)
从 Context 获取字符串资源:
context.getString(R.string.hello)
从 Application 获取字符串资源:
application.getString(R.string.hello)
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1642052次
积分:13478
积分:13478
排名:第901名
原创:163篇
转载:213篇
评论:158条
(2)(1)(2)(4)(4)(2)(2)(3)(2)(10)(1)(1)(1)(3)(1)(1)(7)(8)(7)(7)(1)(1)(14)(14)(2)(1)(8)(50)(6)(3)(11)(23)(25)(14)(7)(29)(24)(25)(20)(27)(9)My dad likes to watch his movies and he has a lot of them.
He keeps his discs in several binders but there is no system of cataloging at all.
I thought I'd make an android app to help him find them
So i thought id store the information in a string array in strings.xml
&?xml version="1.0" encoding="utf-8"?&
&resources&
&string name="hello"&Hello World, MovieFinderActivity!&/string&
&string name="app_name"&MovieFinder&/string&
&string name="movie_prompt"&Choose Movie&/string&
&string-array name="all_movies_array"&
&item binder="1" page="1"&Star Wars Episode 1: The Phantom Menace&/item&
&item binder="1" page="1"&Star Wars Episode 2: Attack of the Clones&/item&
&item binder="1" page="1"&Star Wars Episode 3: Revenge of the Sith&/item&
&item binder="1" page="1"&Star Wars Episode 4: A New Hope&/item&
&item binder="1" page="2"&Star Wars Episode 5: The Empire Strikes Back&/item&
&item binder="1" page="2"&Star Wars Episode 6: Return of the Jedi&/item&
&item binder="1" page="2"&Dr Zhivago Side A&/item&
&item binder="1" page="2"&Dr Zhivago Side B&/item&
&/string-array&
&/resources&
then i did this
movie_spinner = (Spinner) findViewById(R.id.search_movie_spinner);
movie_spinner.setAdapter(adapter2);
movie_spinner.setOnItemSelectedListener((OnItemSelectedListener) this);
and this gets called here
public void onItemSelected(AdapterView&?& arg0, View arg1, int arg2,
long arg3) {
//movie_title is a textview
movie_title.setText( movie_spinner.getSelectedItem() + "");
so whenever a movie gets selected in the spinner, the TextView of movie_title changes to the movie's name
What i want to know is how to retrieve the attributes of binder and page from the node item
解决方案 AFAIK, you are not able to get attribute values for the resources string array.
The way I see it is that you can have the following options
Create an xml file with you data as sherif mentioned.
&item binder="1" page="1"&Star Wars Episode 1: The Phantom Menace&/item&
&item binder="1" page="1"&Star Wars Episode 2: Attack of the Clones&/item&
&item binder="1" page="1"&Star Wars Episode 3: Revenge of the Sith&/item&
&item binder="1" page="1"&Star Wars Episode 4: A New Hope&/item&
&item binder="1" page="2"&Star Wars Episode 5: The Empire Strikes Back&/item&
You could use any f the avaliable parsers like DOM,SAX to parse this and create an arraylist or object of your choice.
Create json data instead of xml and use GSON to parse to to a usable object.
本文地址: &
我爸爸喜欢看他的电影,他有很多。他保持光盘在几个粘合剂,但也没有编目所有的系统。 我想我会做一个Android应用程序,以帮助他找到他们。所以我想ID存储中的信息在strings.xml中的字符串数组 <?XML版本=“1.0”编码=“UTF-8”&GT?;<资源>
<字符串名称=“你好”>的Hello World,MovieFinderActivity<!/串>
<字符串名称=“APP_NAME”>的MovieFinder< /串>
<字符串名称=“movie_prompt”>选择电影< /串>
<字符串数组名=“all_movies_array”>
<项目粘结剂=“1”页面=“1”>星战前传1:幽灵的威胁和LT; /项目>
<项目粘结剂=“1”页面=“1”>星战前传2:克隆&LT的攻击; /项目>
<项目粘结剂=“1”页面=“1”>星战前传3:西斯&LT的复仇; /项目>
<项目粘结剂=“1”页面=“1”>星球大战4:新希望< /项目>
<项目粘结剂=“1”页=“2”>星球大战5:帝国反击< /项目>
<项目粘结剂=“1”页=“2”>星球大战6:绝地&LT的回报; /项目>
<项目粘结剂=“1”页=“2”>日瓦戈端DR< /项目>
<项目粘结剂=“1”页=“2”>日瓦戈B面博士< /项目>
< /字符串数组>< /资源> 那么我这样做
movie_spinner =(微调)findViewById(R.id.search_movie_spinner);
movie_spinner.setAdapter(适配器2);
movie_spinner.setOnItemSelectedListener((OnItemSelectedListener)本); 和这个被这里叫做 公共无效onItemSelected(适配器视图<>为arg0,ARG1观,诠释ARG2,
// MOVIE_TITLE是一个TextView
movie_title.setText(movie_spinner.getSelectedItem()+“”);} 所以每当一部电影的微调被选中的MOVIE_TITLE更改影片的名字的TextView 我想知道的是如何从节点检索粘合剂和页面的属性的项目的解决方案 据我所知,你是不是能够得到属性的资源字符串数组值。我看到它的方式是,你可以有如下选择 与您的数据创建一个XML文件作为谢里夫提及。例如, <电影和GT;
<项目粘结剂=“1”页面=“1”>星战前传1:幽灵的威胁和LT; /项目>
<项目粘结剂=“1”页面=“1”>星战前传2:克隆&LT的攻击; /项目>
<项目粘结剂=“1”页面=“1”>星战前传3:西斯&LT的复仇; /项目>
<项目粘结剂=“1”页面=“1”>星球大战4:新希望< /项目>
<项目粘结剂=“1”页=“2”>星球大战5:帝国反击< /项目>< /电影和GT; 您可以使用任何F中的avaliable解析器如DOM,SAX解析这个并创建你选择的ArrayList或对象。
创建JSON数据,而不是XML和使用GSON解析到一个可用的对象。
本文地址: &
扫一扫关注官方微信

我要回帖

更多关于 路由器的摆放位置 的文章

 

随机推荐