0
votes

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.

  1. The number of words to be entered is set to 4 in the macro NUM.

  2. 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.

  3. The variable for the new string is a one-dimensional array of character type newstr.

  4. Connect the entered words to create a new string newstr, with a space between the words.

  5. Insert one period at the end of the newstr string (no space; see execution example).

  6. 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).

  7. 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

Error

1
On a first glance :- strcpy() is defined in string.h, So include that. - 0_0perplexed
The warnings and errors are quite straight-forward. Why don't you solve it one by one? - mch
Please provide descriptive title and add relevant information to the body. Your numbering 5.3 is not meaningfull to anyone except for you. Also your task description is not relevant as a compiler error does not care about the purpose or your program. Limiting to the relevant information will attract more readers as they don't have to wade through a page of text just to learn that it is not related to your error at all. - Gerhardh
I edit the source. Look this! - MonSorcy

1 Answers

0
votes

Can't simply write a comment because not enough rep but your compiler error says to include <string.h>. Hopefully that's all you'd need.