C
c strings
Guest
I cannot figure out why my strcmp won't cout at all, any advice or help is appreciated!
#include<iostream>
#include<cstring>
#include<ctype.h>
#include<stdio.h>
int my_strcmp(char*, char*);
char* my_strcpy(char*, char*);
using namespace std;
int main(int argc, char* argv[]) {
char* str1 = argv[1];
char* str2 = argv[2];
my_strcmp(str1, str2);
cout << str1 << endl;
cout << str2 << endl;
my_strcpy(str1, str2);
cout << str1 << endl;
cout << str2 << endl;
return 0;
}
int my_strcmp(char* str1, char* str2) {
char k;
char j;
char s;
while(str1) {
k = str1;
putchar (tolower(k));
i++;
}
while(str2[j]) {
j = str2[j];
putchar (tolower(s));
j++;
}
cout << str1 << " and " << str2 << endl;
if (strcmp(str1, str2) == 0) {
return 0;
} //str1 and str2 are equivalent
if (strcmp(str1, str2) > 0) {
return -1;
} //str1 appears before str2 in an alphabetical ordering
if (strcmp(str1, str2) < 0) {
return 1;
} //str1 appears after str2
}
char* my_strcpy(char* str1, char* str2) {
int i;
for(i = 0; i < strlen(str2); i++) {
str1 = str2;
str1 = '\0';
//cout << str1 << endl;
return str1;
}
}
Continue reading...
#include<iostream>
#include<cstring>
#include<ctype.h>
#include<stdio.h>
int my_strcmp(char*, char*);
char* my_strcpy(char*, char*);
using namespace std;
int main(int argc, char* argv[]) {
char* str1 = argv[1];
char* str2 = argv[2];
my_strcmp(str1, str2);
cout << str1 << endl;
cout << str2 << endl;
my_strcpy(str1, str2);
cout << str1 << endl;
cout << str2 << endl;
return 0;
}
int my_strcmp(char* str1, char* str2) {
char k;
char j;
char s;
while(str1) {
k = str1;
putchar (tolower(k));
i++;
}
while(str2[j]) {
j = str2[j];
putchar (tolower(s));
j++;
}
cout << str1 << " and " << str2 << endl;
if (strcmp(str1, str2) == 0) {
return 0;
} //str1 and str2 are equivalent
if (strcmp(str1, str2) > 0) {
return -1;
} //str1 appears before str2 in an alphabetical ordering
if (strcmp(str1, str2) < 0) {
return 1;
} //str1 appears after str2
}
char* my_strcpy(char* str1, char* str2) {
int i;
for(i = 0; i < strlen(str2); i++) {
str1 = str2;
str1 = '\0';
//cout << str1 << endl;
return str1;
}
}
Continue reading...