#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int length;
char **lines, buffer[80];
printf("How many lines do you want to enter?.\n");
scanf("%d", &length);
getchar();
lines = (char**)malloc(length * sizeof(char*));
for (i = 0; i < length; ++i) { //Scan user's lines
gets(buffer);
lines[i] = (char*)malloc(strlen(buffer) * sizeof(char) + 1);
if (!lines[i]) { //Check if allocation available
printf("Error! Out of memory!");
return endProgram;
}
strcpy(lines[i], buffer);
}
return 0;
}
I'd like to know why does the gets()
function giving me an error about assuming extern returning int, I'm just trying to scan a string.