Question:
You need to write a string-comparison function?
anonymous
2009-11-04 07:41:59 UTC
Named strNcompare that compares upto ncharacters of a string s1 with a string s2.

The function returns 0, -1, 1 if the n-character portion of
s1 is equal to, less than or greater than the corresponding n-character portion of s2, respectively.
You must use the following function header:
int strNcompare(const char *s1, const char *s2, int n)

*. Do not use any string-manipulation functions of C++ library in your program. So your program can include only to print out your result.

*. Do not use any array subscripting notation in the function strNcompare. You must use pointers and pointer arithmetic.
Write a program that receives the number of characters and two words for comparison, and then shows the result.

** sample input/output 1 **
How many characters do you want to compare? 3
Enter two words: tommy tomato
tommy is equal to tomato



What I've done so far:

#include
using namespace std;



void strNcompare(const char *s1, const char *s2, int n);
main (){


cout<<"How many characters do you want to compare?"<cout<<"Enter two words:"<
Three answers:
Mani S
2009-11-04 08:03:00 UTC
http://pastebin.com/f56f64309



Hope this helps :)
Dan M
2009-11-04 08:09:25 UTC
I'll point you in the right direction by saying that since you can not use string manipulation function you'll have to use the ASCII values of the characters in order to the the comparison. You can do that by casting the char data type to int data type and then seeing which one is greater.
anonymous
2016-10-17 02:20:42 UTC
Why do u favor set of regulations? for my section, I in simple terms favor to shop the string into array and study each and every letter by technique of calculating them. Ex: makes and makas , non similar letter will be divided by technique of entire letters distinctive by technique of one hundred. Then one hundred minus this outcome. subsequently will be like a million/5 * one hundred = 20. Then one hundred - 20 = 80. Output is 80%.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...