Hi
I'm new to programming with C, and am having trouble understanding why my use of the fgets() function does not allow me to input any text from the command line...
I am trying to store a string into the first row of an array (and then will move onto the next row, etc.)
When I execute my program, it simply skips to the next part of my method without letting me input any text, and instead stores a white space in the string.
Thankfully I don't have to worry about going over the allotted amount of space in the array (we are to assume that the user enters a string less than 50 characters)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//creates 2D array to hold input
char matrix [50][50]; //defines character array of [rows][columns]
int length = 0; //stores length of input string
int main(void)
{
int i = 0; //defines column
int j = 0; //defines row
int k = 0; //int referring to char in string
char inputText[50]; //will store input text
// for one row at a time
for (j=0; j<2; j++) {
//stores input as string
printf("Please enter a line of text.\n");
fgets(inputText, sizeof(inputText), stdin);
length = strlen(inputText);
printf("Length of file: %d\n", length);
...
I haven't included the rest of the code, since it is rather long. (Hopefully I have indented/posted this correctly!)
Any help would be greatly appreciated! Thanks in advance