473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Function PLzzzzzzzzzzz


1.Guys how do i write a function similar to the strcmp() in the librar
like some xstrcmp().
2. How do i write another function eg x() which compares two strings
const char *string, const char *strSearch ie
*string="Hai hello"
*strSearch="ai"
I have to search for ai in the string "Hai Hello" and then return "a
Hello" if found or return NULL if not found.
Hope You can guys can help out a newbie if you cannot get me the whol
func get me some prototype atleast so I can work it out.
Also try to get me the first strcmp() func.
regards
Ash
-
ash464
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 14 '05 #1
6 1392
ash4640 wrote:
1.Guys how do i write a function similar to the strcmp() in the library
like some xstrcmp().
#include <string.h>
int xstrcmp(const char *p, const char *q) {
return strcmp(p, q);
}
2. How do i write another function eg x() which compares two strings
const char *string, const char *strSearch ie
*string="Hai hello"
*strSearch="ai"
I have to search for ai in the string "Hai Hello" and then return "ai
Hello" if found or return NULL if not found.
#include <string.h>
char *xstrstr(const char *string, const char *strSearch) {
return strstr(string, strSearch);
}
Hope You can guys can help out a newbie if you cannot get me the whole
func get me some prototype atleast so I can work it out.
Also try to get me the first strcmp() func.
regards
Ash.
And in a follow-up post, ash4646 wrote: Guys also how would i write a function for converting a decimal no
to a binary and binary to decimal no a prototype is enough.


int dec_to_bin(int x) {
return x;
}

int bin_to_dec(int x) {
return x;
}

Three comments: First, the two string-bashing problems
sound very much like homework, and few Usenet denizens like
to do other people's homework -- we'll usually help you fix
code you've already tried to write, but seldom will we write
it for you. Second, the binary/decimal problem shows either
a fundamental misunderstanding of computer arithmetic or an
inability to state the problem correctly: are you trying to
convert between numbers and strings, or is the goal something
else entirely? Third, asking for help only from "guys" cuts
you off from a potentially valuable resource.

--
Er*********@sun.com

Nov 14 '05 #2
Eric Sosman wrote:
[blatant homework request redacted]
Three comments: First, the two string-bashing problems
sound very much like homework, and few Usenet denizens like
to do other people's homework -- we'll usually help you fix
code you've already tried to write, but seldom will we write
it for you.


Well, if he had posted his professor's address so that we could mail it
directly to the prof.... :)
Nov 14 '05 #3
ash4640 wrote:

1.Guys how do i write a function similar to the strcmp() in the library
like some xstrcmp().


Most of use some sort of text editor to produce C code. This can be a
stand-alone editor for a command-line compiler, or part of an integrated
development environment.

Hope this helps.


Brian Rodenborn
Nov 14 '05 #4

"ash4640" <as************@mail.codecomments.com> wrote in message
news:as************@mail.codecomments.com...

1.Guys how do i write a function
When you've learned C, you'll know how to write a function.
similar to the strcmp() in the library
In order for your function to be 'similar', you'll
need to find out what 'strcmp()' does.
like some xstrcmp().
2. How do i write another function eg x() which compares two strings
const char *string, const char *strSearch ie
*string="Hai hello"
*strSearch="ai"
Do the same as above, but look up what the 'strstr()'
function does.
I have to search for ai in the string "Hai Hello" and then return "ai
Hello" if found or return NULL if not found.
IOW if the string is found, return a pointer to it,
otherwise return NULL.

Nit: finding a substring (which is what you describe) is not
the same thing as 'comparing two strings'. Comparing two
strings is what 'strcmp()' (and hopefully eventually your
version of it) does.
Hope You can guys can help out a newbie
We'll certainly help, but we won't do it for you. Post
your code and ask specific questions.
if you cannot get me the whole
func get me some prototype atleast so I can work it out.
Prototypes (based upon those of the corresponding standard
library functions):

int xstrcmp(const char *s1, const char *s2);
const char *xstrstr(const char *s, const char *to_find);
Also try to get me the first strcmp() func.


No, we won't do it for you. Post your best attempt
and ask specific questions.

-Mike
Nov 14 '05 #5

"ash4640" <as************@mail.codecomments.com> wrote

1.Guys how do i write a function similar to the strcmp() in the library
like some xstrcmp().
Do you understand what a prototype is? It tells the compiler, and
secondarily the human programmer, what the function returns and what
parameters it takes. So for instance a function to calculate a sine would
take a double (in degrees or radians) and return a double.

prototype:
double sine(double radians);

Your prototype for xstrcmp() should be exactly the same as the prototype for
strcmp().
2. How do i write another function eg x() which compares two strings
const char *string, const char *strSearch ie
*string="Hai hello"
*strSearch="ai"
I have to search for ai in the string "Hai Hello" and then return "ai
Hello" if found or return NULL if not found.
Hope You can guys can help out a newbie if you cannot get me the whole
func get me some prototype atleast so I can work it out.
Also try to get me the first strcmp() func.

Getting the prototype written is half the battle. This should always be the
first thing you write, when writing a function.

For general string manipulation, chars are just small variables which
conventionally contain character information. Howver then can be compared
like other functions.
You also need to understand how to increment pointers. In C, strings are
null-terminated, so you need to increment the pointer you are passed,
examining each character, until you come to the NUL, which indicates the end
of the string.

Then both of these functions should be easy to write.
Nov 14 '05 #6
Eric Sosman <Er*********@sun.com> wrote in message news:<41**************@sun.com>...
ash4640 wrote:
1.Guys how do i write a function similar to the strcmp() in the library
like some xstrcmp().


#include <string.h>
int xstrcmp(const char *p, const char *q) {
return strcmp(p, q);
}
2. How do i write another function eg x() which compares two strings
const char *string, const char *strSearch ie
*string="Hai hello"
*strSearch="ai"
> I have to search for ai in the string "Hai Hello" and then return "ai
> Hello" if found or return NULL if not found.


#include <string.h>
char *xstrstr(const char *string, const char *strSearch) {
return strstr(string, strSearch);
}
Hope You can guys can help out a newbie if you cannot get me the whole
func get me some prototype atleast so I can work it out.
Also try to get me the first strcmp() func.
regards
Ash.


And in a follow-up post, ash4646 wrote:
> Guys also how would i write a function for converting a decimal no
> to a binary and binary to decimal no a prototype is enough.


int dec_to_bin(int x) {
return x;
}

int bin_to_dec(int x) {
return x;
}

Three comments: First, the two string-bashing problems
sound very much like homework, and few Usenet denizens like
to do other people's homework -- we'll usually help you fix
code you've already tried to write, but seldom will we write
it for you. Second, the binary/decimal problem shows either
a fundamental misunderstanding of computer arithmetic or an
inability to state the problem correctly: are you trying to
convert between numbers and strings, or is the goal something
else entirely? Third, asking for help only from "guys" cuts
you off from a potentially valuable resource.


Third, asking for help only from "guys" cuts you off from a
potentially valuable resource.

one of those funniest statements, had a hearty laugh, thanks pal.

-Paul
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
1
by: ash4640 | last post by:
Guys also how would i write a function for converting a decimal no to binary and binary to decimal no a prototype is enough - ash464...
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.