Question

How do strings relate to arrays? name at least one string function and explain what it...

How do strings relate to arrays? name at least one string function and explain what it does.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

How string relate to the array? • String is a sequence of characters with single data type. • Array is a collection of an ele

String Functions: • strcat() - used for concatenation of two string • strlen() - used for find the length of a string • strcm

code:

1 #include <stdio.h> #include<string.h> int main() char str1[]=hello; char str2[]=World; /*find the length of string usin

output:

length of strl is : 5 length of str2 is : 5 Strl before concate: hello Strl after concate: helloWorld ... Program finished wi

explain:

strcat() : add str2 into str1.means it is do concatination of two string.

strlen(): find the length of a string.

code in c:

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

int main()
{
char str1[]="hello";
char str2[]="World";
  
/*find the length of string using a length function*/
int n1=strlen(str1);
int n2=strlen(str2);
  
printf("length of str1 is : %d\n",n1);
printf("length of str2 is : %d\n",n2);

/*concate str1 with str2*/
printf("Str1 before concate: %s\n",str1);
strcat(str1,str2);
printf("Str1 after concate: %s\n",str1);
  

return 0;
}

Add a comment
Know the answer?
Add Answer to:
How do strings relate to arrays? name at least one string function and explain what it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT