leer string en c

To read a string in C, you can use the scanf function along with the %s format specifier. Here are the steps to read a string in C:

  1. Include the necessary header file:
#include <stdio.h>
  1. Declare a character array to store the string:
char str[100];

In this example, we are declaring a character array str with a size of 100. You can adjust the size according to your needs.

  1. Use the scanf function to read the string:
scanf("%s", str);

In this step, the scanf function is used with the %s format specifier to read the input string from the user. The string will be stored in the str array.

That's it! The string has been successfully read into the str array. You can now use the str array in your program as needed.