{
newone[ctr] = orig[ctr];
}
}
- The following is one of many possible answers:
#include <stdio.h>
#include <string.h>
/ function prototypes /
char compare_strings( char , char );
int main( void )
{
char a = “Hello”;
char b = “World!”;
char longer;
longer = compare_strings(a, b);
printf( “The longer string is: %s\n”, longer );
return 0;
}
char * compare_strings( char * first, char * second)
{
int x, y;
x = strlen(first);
y = strlen(second);
if( x > y)
return(first);
else
return(second);
}
- This exercise was on your own!
8.a_stringis declared as an array of 10 characters, but it’s initialized with a string
larger than 10 characters. a_stringneeds to be bigger. - If the intent of this line of code is to initialize a string, it is wrong. You should use
eitherchar *quoteorchar quote[100]. - No.
- Yes. Although you can assign one pointer to another, you can’t assign one array to
another. You should change the assignment to a string-copying command such as
strcpy().
856 Appendix F
49 448201x-APP F 8/13/02 11:22 AM Page 856