string array input in c

Language: C - String Array Input in C

To take input for a string array in C, you can follow the steps below:

  1. Declare the String Array:
  2. Start by declaring the string array with a fixed size or using dynamic memory allocation.
  3. Example: c char strings[5][20]; // Declaring a string array of 5 strings, each with a maximum length of 20 characters

  4. Take Input for Each String:

  5. Use a loop to take input for each string in the array.
  6. Example: c for (int i = 0; i < 5; i++) { printf("Enter string %d: ", i+1); scanf("%s", strings[i]); }

  7. Accessing the Input Strings:

  8. After taking input, you can access the strings in the array for further processing or display.
  9. Example: c for (int i = 0; i < 5; i++) { printf("String %d: %s\n", i+1, strings[i]); }

  10. Complete Example:

  11. Here's a complete example demonstrating the input and access of a string array in C: ```c #include

    int main() { char strings[5][20]; for (int i = 0; i < 5; i++) { printf("Enter string %d: ", i+1); scanf("%s", strings[i]); } for (int i = 0; i < 5; i++) { printf("String %d: %s\n", i+1, strings[i]); } return 0; } ```

Remember to adjust the array size and string length according to your specific requirements.