stremp

Can somebody help me to or how start it?
write a program that uses function strcmp to compare two strings input by the user. The program should input the number of characters to compare. The program should state whether the first string is less than, equal to or greater than the second string.
Last edited on
Hi there,

Although your question seems a direct copy from a homework sheet, I'll start things here. The following code will compare two strings and show you the result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main(){
	char string1[] = "good";
	char string2[] = "bad";
	
	int result;
	result = strcmp( string1, string2 );
	
	switch( result ){
		case ( 1 ):
			cout << "First string is greater than second string " << endl;
			break;
		case ( 0 ):
			cout << "First string is equal to second string " << endl;
			break;
		case ( -1 ):
			cout << "First string is less than second string " << endl;
	}
	return 0;
}


You will still need to know how to input the number of characters to compare (using cin) and then how to extract from each string only that number of characters into two new strings, and compare these last new strings instead of the original strings. Good luck.

Thank you, I can start with this.
I am having trouble to do those array, can some body help me? please

Write a C++ program that call a function comp_vec( ) . It should return 1 if vectors v1 and v2 are equal, and 0 otherwise, n is the length of the vectors, and the function prototype will be int com_vec (int v1[ ] , int v2[ ], int n);

Note: a vector is equivalent to a one-dimensional array.

Write a program with two functions. The program works with an integer two-dimensional array of size n x n, where the maximum value of n is 10.
• The first function calculates the sum of all elements of the second row of the array. Function prototype is
int addition_second_row (int matrix [ ][n], int row, int col);
• The second function creates a new array with all elements of the lower triangular matrix that are different from zero. Function prototype is

int new_array (int matrix [ ][n], int row, int col, new_m [ ]);
Hi rserrano,
you need to start writing some code yourself otherwise you will never learn how. People here are happy to offer help and corrections where you are stuck or make mistakes but can't help if you do nothing for them to help on.
You also now have three different questions in the same post, which makes it confusing for everyone - I suggest you edit the extra questions out and post as seperate questions - with whatever partial solutions you have.
Topic archived. No new replies allowed.