473,387 Members | 1,374 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,387 software developers and data experts.

problem on implementing pointer on string

16
Hi,
I have a problem in writing a code using pointer.My assignment is to create a function that compre 2 strings by using a pointer.It returns 1 if they are different and 0 if they are the same.I come up with the following code,but i cann't implement pointer ,please help me in modifying it.The existing code has some bugs but i couldn't identify where is it
Expand|Select|Wrap|Line Numbers
  1. void main() {
  2.      char str1;
  3.      char str2;
  4.      cout<<"Enter the first string";
  5.      cin>>str1;
  6.      cout<<"Enter the second string";
  7.      cin>>str2;
  8.      compstr(str1,str2);
  9. }
  10. void compstr(char s1,char s2){
  11.  if(strcmp(s1,s2)==0){
  12.  return 1;
  13. else 
  14.  return 0;
  15. }
Feb 20 '07 #1
3 1405
Manjiri
40
Hi,
I have a problem in writing a code using pointer.My assignment is to create a function that compre 2 strings by using a pointer.It returns 1 if they are different and 0 if they are the same.I come up with the following code,but i cann't implement pointer ,please help me in modifying it.The existing code has some bugs but i couldn't identify where is it
void main(){
char str1;
char str2;
cout<<"Enter the first string";
cin>>str1;
cout<<"Enter the second string";
cin>>str2;
compstr(str1,str2);
}
void compstr(char s1,char s2){
if(strcmp(s1,s2)==0){
return 1;
else
return 0;
}


Hello Friend..

You want to do it by using pointers right...?
Then first use two character pointers...
Use two char variables to read the two strings..
Assign their addresses to character pointers..
Now pass their address to function by using poiter variables...

Function strcmp will return 0 if they are equal else any nonzero integer..
Here you are returning value 1 if they are equal where it is totally opposite of what you require( value 1 should be returned if they are different as you mentioned) So change this also...

Try it...
All the best...
Feb 20 '07 #2
Ganon11
3,652 Expert 2GB
Also, I think using strcmp within your compstr function is kind of pointless - if you were allowed to use strcmp, you could just use it rather than hiding it within your own function. My guess is that you need to write your own version of strcmp without using it.
Feb 20 '07 #3
Banfa
9,065 Expert Mod 8TB
Also you are trying to return a value from a void function.
Feb 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matias S | last post by:
Hello! I am implementing a dictionary, in C++, for my school assignment. But when I am testing my Item class (this is what the dictionary is supposed to store), I get a strange error message...
2
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
11
by: ajay.sonawane | last post by:
Hello ther I read somewhere that callback function should be global or static member function. 1: I could use static member functions but how could I access members of class which ar not static....
7
by: Amar | last post by:
I am trying to connect to my college LDAP directory using ASP.NET. This LDap does not have security as it returns only user demographic information. i do not need to bind with a username or...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
5
by: Eric | last post by:
I am implementing a variation on the Singleton design pattern, that allows up to 8 objects of a class to be instantiated, and returns a null pointer for anything more than 8. I am running into a...
13
by: Tristan Wibberley | last post by:
Hi I've got implementing overloaded operator new and delete pretty much down. Just got to meet the alignment requirements of the class on which the operator is overloaded. But how does one...
10
by: hsmit.home | last post by:
Hi everyone, I'm having some difficulty with the following piece of code. I have stripped it to it's bare minimum to demonstrate the problem at hand. Compiler: MS Visual C++ 2005 Express...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.