Question: Write in C language. 1. Using string_printer()as a model, as a new function that determines the size of the string by counting all of its
Write in C language.
1. Using string_printer()as a model, as a new function that determines the size of the string by counting all of its characters.
Test this function in main() by passing to it all of the strings that have been declared there, including the empty string.
Remember to write sentence output in main().
Starting code:
#include
#include
void string_printer(char new_string[])
{
char *sp = new_string;
while (*sp != '\0')
{
//print and increment the sp
printf("%c", *sp);
sp++;
}
}
int main()
{
// array size 9
char new_string[10] = "Chocolate";
//array size 10
char new_string1[11] = "Chocolates";
//array size 8
char new_string2[9] = "absolute";
//array size 6
char new_string3[7] = "accent";
//array size 0
char new_string4[1] = "";
printf("String1 contains %s ", new_string);
printf("String2 contains %s ", new_string1);
printf("String3 contains %s ", new_string2);
printf("String4 contains %s ", new_string3);
printf("String5 contains %s ", new_string4);
printf("------------------------------------- ");
printf("String1 contains (using pointer):");
string_printer(new_string);
printf(" ");
printf("String2 contains (using pointer):");
string_printer(new_string1);
printf(" ");
printf("String3 contains (using pointer):");
string_printer(new_string2);
printf(" ");
printf("String4 contains (using pointer):");
string_printer(new_string3);
printf(" ");
printf("String5 contains (using pointer):");
string_printer(new_string4);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
