Register for your free account! | Forgot your password?

You last visited: Today at 09:54

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



strmp

Discussion on strmp within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2014
Posts: 2
Received Thanks: 0
strmp

Code:
// (zahl) wurde global deklariert
int str_cmp(const char*c_buchstaben1[], const char* c_buchstaben[])
{
	while ((*c_buchstaben1[zahl]) == (*c_buchstaben[zahl]))
	{
		if (c_buchstaben1[(zahl == 199)])
		{
			return 0;
		}
		else if ((*c_buchstaben1[zahl]) < (*c_buchstaben[zahl]))
		{
			return -1;
		}
		else if ((*c_buchstaben1[zahl]) > (*c_buchstaben[zahl]))
		{
			return 1;
		}
	}
	zahl + 1;
}
das soll die funktion strcmp darstellen ist so richtig?
Kiasho is offline  
Old 07/08/2014, 13:40   #2
 
elite*gold: 46
Join Date: Oct 2010
Posts: 782
Received Thanks: 525
Nein, weil du const char*[] als Parameter übernimmst.
Hier ist ein Beispiel aus dem Internet, wie die strcmp Funktion aussehen könnte. Und beim nächsten mal könntest du das einfach googlen
Code:
int myStrCmp (const char *s1, const char *s2) {
    const unsigned char *p1 = (const unsigned char *)s1;
    const unsigned char *p2 = (const unsigned char *)s2;

    while (*p1 != '\0') {
        if (*p2 == '\0') return  1;
        if (*p2 > *p1)   return -1;
        if (*p1 > *p2)   return  1;

        p1++;
        p2++;
    }

    if (*p2 != '\0') return -1;

    return 0;
}
Und wenn du zahl1 global hast würde ich zahl1 am Anfang deiner Funktion auf 0 setzen. Ergibt für mich aber überhaupt keinen Sinn das überhaupt global oder in einem int zu speichern. Wie du in dem Beispiel siehst kannst du pointer direkt inkrementieren.
th0rex is offline  
Reply




All times are GMT +1. The time now is 09:56.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.