I want to create a program that combines several words entered from the keyboard into a single string. However, I get a compile error. The contents of the program.
The number of words to be entered is set to 4 in the macro NUM.
The length of the word to be entered shall be 20 characters or less (including null characters). A two-dimensional character array is used for input.
The variable for the new string is a one-dimensional array of character type newstr.
Connect the entered words to create a new string newstr, with a space between the words.
Insert one period at the end of the newstr string (no space; see execution example).
Print the created newstr as a whole with printf. Do not insert spaces or periods in printf at this time. Finally, the number of characters of newstr (including the space period) is displayed and the process ends (see the execution example).
You can use the strcpy and strlen functions. The strcpy function is a function that copies the character string specified in the second argument after the address specified in the first argument. The strlen function is a function that returns the length of a character string (not including null characters). When using it, first include string.h.
source
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#define NUM 4
int main ()
{
char str2 [NUM] [20]; / * Character array for input * /
char newstr [100]; / * Character array for output * /
int i;
printf ("Input% d words: \ n", NUM);
for (i = 0; i <NUM; i ++) {
printf ("% s", str2 [i]); / * Print original string * /
}
for (i = 0; i <NUM; i ++) {
strcpy (newstr [i], str [i]);
if ('A' <= str2 [i] [0] && str2 [i] [0] <='Z')
newstr [i] [0] = str2 [i] [0] + 32;
// else break;
printf ("% s \ n", newstr [i]);
}
// newstr [i] = * prefix + str [i];
// for (i = 0; i <NUM; i ++) {
// printf ("% s \ n", newstr [i]); / * Display newly created string * /
//}
return 0;
}...
Error