D
Darklight
Q6: Write a function that accepts two strings. Count the number of
characters in each, and return a pointer to the longer string.
and please comment
/* LEN_STRING.C PROGRAM TO RETURN LONGEST STRING */
#include<stdio.h>
#include<string.h>
void length(char [ ], char [ ]);
int main(void)
{
char a[100];
char b[100];
printf("Enter string1\n");
fgets(a,100,stdin);
printf("Enter string2\n");
fgets(b,100,stdin);
length(a,b);
return 0;
}
void length(char string1[ ], char string2[ ])
{
char *line;
if((strlen(string1)) > (strlen(string2)))
{
line = string1;
printf("\nstring 1 is the longest\n%s\n",line);
}
else if(strlen(string1) < strlen(string2))
{
line = string2;
printf("\nstring 2 is the longest\n%s\n",line);
}
else
printf("\nBoth strings are the same length\n");
}
characters in each, and return a pointer to the longer string.
and please comment
/* LEN_STRING.C PROGRAM TO RETURN LONGEST STRING */
#include<stdio.h>
#include<string.h>
void length(char [ ], char [ ]);
int main(void)
{
char a[100];
char b[100];
printf("Enter string1\n");
fgets(a,100,stdin);
printf("Enter string2\n");
fgets(b,100,stdin);
length(a,b);
return 0;
}
void length(char string1[ ], char string2[ ])
{
char *line;
if((strlen(string1)) > (strlen(string2)))
{
line = string1;
printf("\nstring 1 is the longest\n%s\n",line);
}
else if(strlen(string1) < strlen(string2))
{
line = string2;
printf("\nstring 2 is the longest\n%s\n",line);
}
else
printf("\nBoth strings are the same length\n");
}