Hi, I'm in C, and I have a little problem with the following code. First of all, my program simply reads the input from the user and, if there is available memory, it stores it, otherwise it does nothing.
I have an array of pointers to char called "strings" and an array of characters to temporarily store input called "string".
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXWIDTH 81
#define MAXLINES 100
int main ()
{
char* lines [MAXLINES];
char line[MAXWIDTH];
int i ;
int n ;
, , . , , for , .
, , , . ok (!= NULL), () .
for (n = 0; n < MAXLINES && gets(line) != NULL; n++)
{
if ((lines[n] = malloc(strlen(line) + 1)) == NULL)
exit (1);
strcpy(lines[n], line);
}
.
for (i = 0; i < n; i++)
{
puts(lines[n-i-1]);
free(lines[n-i-1]);
}
return 0;
}
, - , , .
infinte, , , - .