需要一些帮助 [英] need some help

查看:85
本文介绍了需要一些帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

i在我去年的问题论文中有一些问题。我需要

帮助我们了解这些问题的逻辑。


1)编写一个C函数,它接受两个字符串作为参数并返回

a指针指向第二个字符串中第一个字符串的第一个字符串或NULL

,如果它不存在。


- 我试图解决它,但似乎我不理解这个

问题。我正在服用这个问题为:


1st string-" cat"

2nd string-我喜欢猫。


i必须返回指针,该指针具有'c''的转换地址。*
第二个字符串。我可以创建一个程序(找到另一个字符串)

但是如何返回该字符串的指针我不知道。

请提出一些建议。


2)写一个''C' 'function

char ** readAndcreate(int n)

函数读取&n;&n QUOT;来自输入的字符串,并使用malloc动态创建一个

这样的字符串列表图书馆电话。

- 以及我知道我必须制作一个链接列表,它将持有

字符串(我可以制作它)但有一件事我没有了解这个

函数将返回的内容,该列表的第一个节点的地址或其他内容

else.if是的请描述如何?


我的英语不好但是我觉得你已经理解了我的问题。如果有人能建议一个与我的问题相关的好链接,我会是

感谢。

感谢提前

:)

hi friends,
i have some questions whch is in my last year question papers.i need
some help to get logic of these questions.

1) write a C function, that takes two strings as arguments and returns
a pointer to the first occurrence of 1st string in 2nd string or NULL
if it is not present.

-- i tried to solve it but it seems that i am not understanding this
question at all.i am taking this question as:

1st string- "cat"
2nd string-"i like cat."

i have to return pointer that has strarting address of ''c'' of cat of
2nd string.i can make a program ( that finds a string into another )
but how to return pointer of that string i don`t know.
please suggest some advice.

2) write a ''C'' function
char **readAndcreate(int n)
the function reads "n" strings from the input and creates a list of
such strings dynamically using "malloc" library call.
-- as well as i understand i have to make a linked list that will hold
the strings(i can make it )but one thing i didn`t understand what this
function will return, Address of first node of that list or something
else.if yes please describe how?

my english is not good but i think you have understood my problems.if
anyone can suggest a good link related to my problems, i will be
thankful.
thankx in advance
:)

推荐答案

ash说:
ash said:
嗨朋友们,
我在去年的问题论文中有一些问题。我需要一些帮助来获得这些问题的逻辑。

1)编写一个C函数,它接受两个字符串作为参数,并返回指向第二个字符串中第一个字符串第一个出现的指针,如果不存在则返回NULL



好​​吧,无论如何,这个很容易。


#include< string.h>

char * ashstrstr(char * haystack,char * needle)

{

返回strstr(haystack,needle);

}

2)写一个''C''函数
char ** readAndcreate(int n)
函数读取n。来自输入的字符串,并使用malloc动态创建一个动态列表。图书馆电话。
- 据我所知,我必须制作一个链接列表,它将保持字符串(我可以制作它)但有一件事我不明白这是什么
函数将返回,该列表的第一个节点的地址或其他东西
else。如果是,请描述如何?
hi friends,
i have some questions whch is in my last year question papers.i need
some help to get logic of these questions.

1) write a C function, that takes two strings as arguments and returns
a pointer to the first occurrence of 1st string in 2nd string or NULL
if it is not present.
Well, that one''s easy, at any rate.

#include <string.h>
char *ashstrstr(char *haystack, char *needle)
{
return strstr(haystack, needle);
}
2) write a ''C'' function
char **readAndcreate(int n)
the function reads "n" strings from the input and creates a list of
such strings dynamically using "malloc" library call.
-- as well as i understand i have to make a linked list that will hold
the strings(i can make it )but one thing i didn`t understand what this
function will return, Address of first node of that list or something
else.if yes please describe how?




如果它要求链表,它会这么说,并且原型中会出现某种链接列表,并且它没有b $ b并且它没有它不是。


不,它正在寻找的是:


1)设置你的n数组char *对象,如下所示:


char ** new = malloc(n * sizeof * new);

if(new!= NULL)

{


2)下一阶段是编写(或找到)一个可以从标准输入读取整个

行的函数,在必要时重新分配存储空间以确保有足够的空间存放字符串。对于一个非常简单的方法来做这个非常适合你的方法,找一下Chuck Falconer的
ggets()函数,我听说,这个函数可能是发现于:


< http://cbfalconer.home.att.net/download/ggets.zip>


3)简单在循环中调用此函数,将由此获得的每个指针分配给new [i],其中i是您的循环计数器,从0运行到n-1。如果函数返回NULL,表示存储空间不足,或者

可能缺少输入数据,那么你将会做什么?


4)返回新的;

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)



If it were asking for a linked list, it would have said so, and there would
have been some kind of linked list thingy in the prototype, and it didn''t
and there isn''t so it isn''t.

No, what it''s looking for is this:

1) set up your array of n char * objects, like this:

char **new = malloc(n * sizeof *new);
if(new != NULL)
{

2) the next stage is to write (or find) a function that can read an entire
line from standard input, reallocating storage as and when necessary to
ensure that there is sufficient room to store the string. For a very simple
way to do this that will suit you very well, look for Chuck Falconer''s
ggets() function which, last I heard, could be found at:

<http://cbfalconer.home.att.net/download/ggets.zip>

3) simply call this function in a loop, assigning each pointer thus obtained
to new[i], where i is your loop counter, running from 0 to n-1. What will
you do if the function returns NULL, to indicate insufficient storage, or
perhaps an absence of input data?

4) return new;
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)




" ;理查德希思菲尔德 <在***** @ invalid.invalid>在留言中写道

news:dc ******************** @ bt.com ...

"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:dc********************@bt.com...
ash说:
ash said:
嗨朋友们,
我在去年的问题论文中有一些问题。我需要一些帮助来解决这些问题的逻辑。< 1)编写一个C函数,它接受两个字符串作为参数,并返回指向第二个字符串中第一个第一个字符串的指针,如果不存在则返回NULL

好吧,无论如何,这个很容易。

#include< string.h>
char * ashstrstr(char * haystack,char * needle)
{
返回strstr(haystack,needle);
}
hi friends,
i have some questions whch is in my last year question papers.i need
some help to get logic of these questions.

1) write a C function, that takes two strings as arguments and returns
a pointer to the first occurrence of 1st string in 2nd string or NULL
if it is not present.
Well, that one''s easy, at any rate.

#include <string.h>
char *ashstrstr(char *haystack, char *needle)
{
return strstr(haystack, needle);
}




这是错误的。它应该是strstr(针,干草堆)。

指令是在s2中找到s1的第一次出现。

strstr在s1中找到第一个s2。


对于这个作业,我认为教练真的想要学生写一些strstr的内部结构。如果是这样,他/她

应该明确声明不允许使用strstr。



This is wrong. It should be strstr(needle, haystack).
The instruction was to find first occurence of s1 in s2.
strstr finds first s2 in s1.

For this homework, I think the instructor really wants
the student to write the internals of strstr. If so, he/she
should have explicitly stated that using strstr was not allowed.

2)写一个''C''函数 char ** readAndcreate(int n)
函数读取n。来自输入的字符串,并使用malloc动态创建一个动态列表。图书馆电话。
- 据我所知,我必须制作一个链接列表,它将保持字符串(我可以制作它)但有一件事我不明白这是什么
函数将返回,该列表的第一个节点的地址或其他东西
else。如果是,请描述如何?
2) write a ''C'' function
char **readAndcreate(int n)
the function reads "n" strings from the input and creates a list of
such strings dynamically using "malloc" library call.
-- as well as i understand i have to make a linked list that will hold
the strings(i can make it )but one thing i didn`t understand what this
function will return, Address of first node of that list or something
else.if yes please describe how?



如果它要求链表,它会说所以,原型中会有某种链接列表,而且它没有
并且它不会是这样的。

不,它正在寻找的是:

1)设置n个char *对象的数组,如下所示:

char ** new = malloc(n * sizeof * new);
if(new!= NULL)
{/ /
2)下一阶段是写(或找到)可以从标准输入读取整个
线的功能,在必要时重新分配存储空间以确保有足够的空间存储字符串。对于一个非常简单的方法,这样做非常适合你,查找Chuck Falconer的
ggets()函数,我听说,最后可以找到:

< http://cbfalconer.home.att.net/download/ggets.zip>

3)简单地在循环中调用此函数,分配每个指针因此<获得
到new [i],其中i是你的循环计数器,从0到n-1。如果函数返回NULL,表示存储空间不足,或者可能缺少输入数据,你会做什么?

4)返回新的;

-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)



If it were asking for a linked list, it would have said so, and there
would
have been some kind of linked list thingy in the prototype, and it didn''t
and there isn''t so it isn''t.

No, what it''s looking for is this:

1) set up your array of n char * objects, like this:

char **new = malloc(n * sizeof *new);
if(new != NULL)
{

2) the next stage is to write (or find) a function that can read an entire
line from standard input, reallocating storage as and when necessary to
ensure that there is sufficient room to store the string. For a very
simple
way to do this that will suit you very well, look for Chuck Falconer''s
ggets() function which, last I heard, could be found at:

<http://cbfalconer.home.att.net/download/ggets.zip>

3) simply call this function in a loop, assigning each pointer thus
obtained
to new[i], where i is your loop counter, running from 0 to n-1. What will
you do if the function returns NULL, to indicate insufficient storage, or
perhaps an absence of input data?

4) return new;
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)



-

Fred L. Kleinschmidt

波音助理技术研究员

技术架构师,软件重用项目


--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


" Richard Heathfield"写道:
"Richard Heathfield" wrote:
ash说:
ash said:
嗨朋友们,
我在去年的问题论文中有一些问题。需要一些帮助来获得这些问题的逻辑。

1)编写一个C函数,它接受两个字符串作为参数并返回指向第一个字符串的第一个出现的指针在第二个字符串中为NULL
如果它不存在。
hi friends,
i have some questions whch is in my last year question papers.i need
some help to get logic of these questions.

1) write a C function, that takes two strings as arguments and returns
a pointer to the first occurrence of 1st string in 2nd string or NULL
if it is not present.



那么,无论如何,这个很容易。

#include < string.h>
char * ashstrstr(char * haystack,char * needle)
{
返回strstr(haystack,needle);
}



Well, that one''s easy, at any rate.

#include <string.h>
char *ashstrstr(char *haystack, char *needle)
{
return strstr(haystack, needle);
}




你完全清楚这不是导师想要的。



You know perfectly well that that is not what the instructor wanted.


这篇关于需要一些帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆