Originally Posted by Shotgun
How do i malloc a matrix of [n] rows and [m] colums?
I know I have to use two nested loops but I don't understand how to do it thoe
int **matrix = malloc(NUMBER_OF_ROWS * sizeof(int));
for ( i = 0; i < NUMBER_OF_ROWS; ++i )
matrix[i] = malloc(NUMBER_OF_COLUMES * sizeof(int));
Do you treat your char arrays as strings? If so, how do you test for the end of string? If not, you could test your array for a nl (newline) and remove it. There's various ways...
fgets reads all characters into a char array until it reaches an EOF or nl char, if it reaches a nl char it stores it.
Normaly char arrays I handle don't have nl chars in them, is this a problem?
I would prefer if all my char arrays were consistent and didn't have nl chars in them, how would I do this?
The fgets() function reads at most n-1 characters from stream into the buffer pointed to by s. No additional characters are read after fgets() has read and transferred a newline character to the buffer. A null character is written immediately after the last character that fgets() reads into the buffer.