Code:
fgets(one, i, stdin);
nl = strrchr(one, '\n');
if (nl) *nl = '\0';
if (atoi(one) == -1){
printf("\n");
return 0;
}
fgets(two, i, stdin);
nl = strrchr(two, '\n');
if (nl) *nl = '\0';
if (two[50] == one[50]){
two[50] = NULL;
} else if (atoi(two) == -1){
printf("%s \n", one);
return 0;
}
fgets(three, i, stdin);
nl = strrchr(three, '\n');
if (nl) *nl = '\0';
if (three[50] == two[50] || three[50] == one[50]){
three[50] = NULL;
} else if (atoi(three) == -1){
printf("%s %s \n", one, two);
return 0;
}
fgets(four, i, stdin);
nl = strrchr(four, '\n');
if (nl) *nl = '\0';
if (four[50] == three[50] || four[50] == two[50] || four[50] == one[50]){
four[50] = ' ';
} else if (atoi(four) == -1){
printf("%s %s %s \n", one, two, three);
return 0;
}
fgets(five, i, stdin);
nl = strrchr(five, '\n');
if (nl) *nl = '\0';
if (five[50] == four[50] || five[50] == three[50] || five[50] == two[50] || five[50] == one[50]){
five[50] = ' ';
} else if (atoi(five) == -1){
printf("%s %s %s %s \n", one, two, three, four);
return 0;
}
fgets(six, i, stdin);
nl = strrchr(six, '\n');
if (nl) *nl = '\0';
if (six[50] == five[50] || six[50] == four[50] || six[50]== three[50] || six[50] == two[50] || six[50] ==
one[50]){
six[50] = ' ';
} else if (atoi(six) == -1){
printf("%s %s %s %s %s \n", one, two, three, four, five);
return 0;
}
fgets(seven, i, stdin);
nl = strrchr(seven, '\n');
if (nl) *nl = '\0';
if (seven[50] == six[50] || seven[50] == five[50] || seven[50] == four[50] || seven[50] == three[50] ||
seven[50] == two[50] || seven[50] == one[50]){
seven[50] = ' ';
} else if (atoi(seven) == -1){
printf("%s %s %s %s %s %s \n", one, two, three, four, five, six);
return 0;
}
fgets(eight, i, stdin);
nl = strrchr(eight, '\n');
if (nl) *nl = '\0';
if (eight[50] == seven[50] || eight[50] == six[50] || eight[50] == five[50] || eight[50] == four[50] ||
eight[50] == three[50] || eight[50] == two[50] || eight[50] == one[50]){
eight[50] = ' ';
} else if (atoi(eight) == -1){
printf("%s %s %s %s %s %s %s \n", one, two, three, four, five, six, seven);
return 0;
}
fgets(nine, i, stdin);
nl = strrchr(nine, '\n');
if (nl) *nl = '\0';
if (nine[50] == eight[50] || nine[50] == seven[50] || nine[50] == six[50] ||
nine[50] == five[50] || nine[50] == four[50] || nine[50] == three[50] || nine[50] ==
two[50] || nine[50] == one[50]){
nine[50] = ' ';
} else if (atoi(nine) == -1){
printf("%s %s %s %s %s %s %s %s \n", one, two, three, four, five, six, seven, eight);
return 0;
}
fgets(ten, i, stdin);
nl = strrchr(ten, '\n');
if (nl) *nl = '\0';
if (ten[50] == nine[50] || ten[50] == eight[50] || ten[50] == seven[50] || ten[50] == six[50] || ten[50] ==
five[50] || ten[50] == four[50] || ten[50] == three[50]
|| ten[50] == two[50] || ten[50] == one[50]){
ten[50] = NULL;
} else if (atoi(ten) == -1){
printf("%s %s %s %s %s %s %s %s %s \n", one, two, three, four, five, six, seven, eight, nine);
return 0;
} else {
printf("%s %s %s %s %s %s %s %s %s %s \n", one, two, three, four, five, six, seven, eight, nine, ten);
}
}
Also, the final printf (I thought) would just go ahead and print all ten strings, but if you just enter 10 strings without -1 as the 10th string, the program simply ends. Any ideas?