123k views
0 votes
PROGRAM LANGUAGE C

WRITE CODE YOU
compile a program that loads two strings of characters. Create a new string that connects these two strings to print such a string. Add a \ 0 character to the end of the string and print the string as a string
Sorry for my English.

User TheMethod
by
5.1k points

1 Answer

6 votes

Answer:

I'm better at C++, but I'm pretty sure this it:

/*C - Program to compare two strings

character by character.*/

#include<stdio.h>

int main(){

char str1[]="Hello";

char str2[]="Hello";

int len1=0, len2=0;

int i,isSame=0;

//calculate lengths

i=0;

while(str1[i++]!='\0') len1++;

i=0;

while(str2[i++]!='\0') len2++;

if(len1!=len2){

printf("Strings are not same, lengths are different\\");

return -1;

}

isSame=1;

for(i=0;i<len1;i++){

if(str1[i]!=str2[i]){

isSame=0;

break;

}

}

if(isSame)

printf("Strings are same.\\");

else

printf("Strings are not same.\\");

return 0;

}

User ComfortablyNumb
by
5.0k points