Ir para conteúdo

satineeraj

Members
  • Total de itens

    1
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre satineeraj

  • Data de Nascimento 06/04/1998

Informações Pessoais

  • Sexo
    Masculino
  1. satineeraj

    Strcat Function In C++

    #include <iostream> #include <cstring> using namespace std; // Declare strcat and strlen functions before main char* mystrcat(char* s1, const char* s2); size_t mystrlen(const char* s); int main(int argc, char** argv) { const int MAX = 100; char s1[MAX]; char s2[MAX]; cout << "Enter your first string up to 99 characters: "; cin.getline(s1, sizeof(s1)); int size_s1 = strlen(s1); cout << "Length of first string is " << size_s1 << "\n"; cout << "Enter your second string up to 99 characters: "; cin.getline(s2, sizeof(s2)); int size_s2 = strlen(s2); cout << "Length of second string is " << size_s2 << "\n"; cout << "Now the first string will be concatenated with the second string\n"; char* a = mystrcat(s1, s2); // print the concatenated string cout << a << endl; // system("pause"); return 0; } // strcat function to concatenate two strings char* mystrcat(char* s1, const char* s2) { int indexOfs1 = strlen(s1); int s2L = strlen(s2); int indexOfs2 = 0; do { s1[indexOfs1] = s2[indexOfs2]; indexOfs1++; indexOfs2++; } while (indexOfs2 < s2L); s1[indexOfs1] = '\0'; // add null terminator to the end of the concatenated string return s1; } // Returns length of char array size_t mystrlen(const char* s) { int count = 0; int i; for (i = 0; s != '\0'; i++) { count++; } return count; } You can try this code, and or you can choose a different compiler to run the code. I found this post on the internet; here author listed many cpp compilers, chose any online compiler and run the code.
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.