str function prob 
Author Message
 str function prob

I have written the following sting functions myself but I get a stack
overflow when using them, please help if possible.
#include <system.h>

int mystrncmp(char* s1, char* s2)

{
    int x = 0;
    do {
       if (*s1 != *s2++)
       return (*s1 - *s2);
        if (*s1++ == 0)
         break;
        }
        while (--x != 0);
        return(0);

Quote:
}

#include <system.h>
char* strcat(char* dest, char* src)

{
 {

  char *d = dest;
       char *s = src;
  while (*d != 0)
        d++;
          do {
               if ((*d = *s++) == 0)
               break;
               d++;
               }

             }
     return(d);

 )

both are put in header file :-myString.h

int mystrlen(char *s);
int mystrcmp(char *s1, char *s2);
char *strcpy(char *dest, char*src);
char *strcat(char *dest, char *src);



Thu, 28 Jun 2001 03:00:00 GMT  
 str function prob

   #include <system.h>

No such header.

   int mystrncmp(char* s1, char* s2)

ITYM const char *s1, const char *s2

   {
       int x = 0;
       do {
          if (*s1 != *s2++)
          return (*s1 - *s2);

ITYM return (*s1 - s2[-1]);

           if (*s1++ == 0)
            break;
           }
           while (--x != 0);

Umm what's the point?  The loop will stop, maybe, after x wraps around
to 0.  Shouldn't you have an x argument rather than local var?

           return(0);

   }

   #include <system.h>

No such header.

   char* strcat(char* dest, char* src)

ITYM char *dest, const char *src

   {
    {

     char *d = dest;
          char *s = src;
     while (*d != 0)
           d++;
             do {
                  if ((*d = *s++) == 0)
                  break;
                  d++;
                  }

You need a while clause.  Simpler version would simply be
        while (*d++ = *s++);
by the way.  And you forgot to write the null terminator, too.

                }

        return(d);
    )

   both are put in header file :-myString.h

   int mystrlen(char *s);
   int mystrcmp(char *s1, char *s2);
   char *strcpy(char *dest, char*src);
   char *strcat(char *dest, char *src);
--
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)

Please: do not email me copies of your posts to comp.lang.c
        do not ask me C questions via email; post them instead



Sat, 30 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mem functions versus str functions

2. char **str vs. char *str[]

3. _T(str) vs (CString)str?

4. char *str vs. char str[]

5. Dialogs: m_myCtrl.GetWindowText(str) or GetDlgItemText(IDC_MY_CTRL, str)?

6. mem* versus str* functions

7. str* functions and NULL pointers

8. str* library functions help

9. Calling a VB function from a C dll with a str param

10. c standard regarding char str[ ], str[50] & *str

11. Really (Re: Found prob (Re: typedef function pointers, gcc complains))

12. Overloading function prob with different return types

 

 
Powered by phpBB® Forum Software