I tried to create a strcat function, but it didn't work, so I'm asking you a question.

Asked 2 years ago, Updated 2 years ago, 30 views

I came into mystrcat and copied the address, but the contents don't seem to be copied

#include <stdio.h>
#include <string.h>

char* mystrcat(char* pszDst, char* pszSrc)
{


    while (*pszDst != '\0');
    ++pszDst;
    while (*pszSrc != '\0')
        *pszDst++ = *pszSrc++;

    *++pszDst = '\0';

    return --pszDst;


}
int main() {
    char szPath[128] = { 0 };
    char* pszEnd = NULL;

    pszEnd = mystrcat(szPath, "C:\\Program Files\\");
    pszEnd = mystrcat(pszEnd, "CHS:\\");
    pszEnd = mystrcat(pszEnd, "C programming");

    puts(szPath);
    return 0;


}

strcat c

2022-09-20 18:05

1 Answers

while (*pszDst != '\0');
    ++pszDst;

Delete the semicolon (;) at the end of the while line.

while (*pszDst != '\0')
    ++pszDst;


2022-09-20 18:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.