I'm writing a program that will sort words you input alphabetically, but I found it impossible to progress because the loop doesn't work as intended.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
char string[50][50];
int i, n;
printf("Insert the number of strings: ");
scanf("%d ", &n);
for(i=0; i < n; i++)
{
printf("Insert %d. string: ", i+1);
fgets(string[i],50,stdin);
}
return 0;
}
I tried using gets() and tried to use fgets(), but the result is the same. It prints:
Insert 1. string: Insert 2. string:
Then you can insert strings, but 1 less than specified.