how to input till end of line in c

To input till the end of a line in C, you can use the fgets() function. Here's an example:

#include <stdio.h>

int main() {
   char input[100];

   printf("Enter a line of text: ");
   fgets(input, sizeof(input), stdin);

   printf("You entered: %s", input);

   return 0;
}

In this example, the fgets() function is used to read a line of text from the user. The function takes three arguments: the input buffer (input), the maximum number of characters to read (sizeof(input)), and the input stream (stdin for standard input). The function reads characters from the input stream until it encounters a newline character or the maximum number of characters is reached.

After reading the input, the program prints the entered line of text using printf().

Please note that the fgets() function includes the newline character ('\n') in the input if it fits within the specified buffer size. If you want to remove the newline character from the input, you can use the strcspn() function. Here's an example:

#include <stdio.h>
#include <string.h>

int main() {
   char input[100];

   printf("Enter a line of text: ");
   fgets(input, sizeof(input), stdin);

   input[strcspn(input, "\n")] = '\0'; // Remove the newline character

   printf("You entered: %s", input);

   return 0;
}

In this example, the strcspn() function is used to find the position of the newline character ('\n') in the input string. The function returns the number of characters before the newline character, which is then used to replace the newline character with a null character ('\0') using array indexing.

I hope this helps! Let me know if you have any further questions.