Hi all, I'm still new to C and would like to ask the following questions. When I use fgets(), does it also reads the '\n' character? What should I do if I would like to print in the following manner.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 50
int main(void)
{
char *input1, *input2;
input1 = malloc(MAXSIZE);
input2 = malloc(MAXSIZE);
printf("Input string 1: ");
fgets(input1, MAXSIZE+1, stdin);
printf("Input string 2: ");
fgets(input2, MAXSIZE+1, stdin);
printf("String 1\t\tString 2\n");
printf("--------------------------------------\n");
printf("%10s", input1);
printf("%10s", input2);
return 0;
}
Also I would like to ask, is it necessary to do casting when I do malloc, as I sometimes see that being done in C programming books that I read. For example:
Code:
char *input1, *input2;
input1 = (char *)malloc(MAXSIZE);
input2 = (char *)malloc(MAXSIZE);
Thanks!