I tried this...Yet i Failed..XrossHair
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int removedups(char str[100][100],int num)
{
for(int i=0;str[i][0]!='\0';i++)
{ if(str[i]==str[i+1])
{
strcpy(str[i+1]," ");
--num;
}
}
return num;
}
void printwords(char str[100][100],int num)
{
for(int i=0;i<num;i++)
printf("\n%s",str[i]);
}
int readfile(char str[100][100], const char *filename) {
FILE * in = fopen(filename,"r");
int n = 0;
while ( fscanf(in,"%s",str[n]) == 1 ) {
n++;
}
fclose(in);
return n;
}
void lowercase(char str[100][100], int numwords ) {
for(int i=0;i < numwords;i++)
strlwr(str[i]);
}
void sortwords(char str[100][100], int numwords ) {
for ( int i = 0 ; i < numwords ; i++ ) {
for(int j=i+1;j < numwords ;j++)
{
if(strcmp(str[i],str[j])>0) // it's not specifically == 1
{
char temp[100];
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}
}
int main()
{
printf("\n\t\t\tSorting Strings\n");
char str[100][100];
int numwords = readfile(str,"input.txt");
// printwords(str, numwords); // use this to make sure the file read OK
lowercase(str, numwords);
// printwords(str, numwords); // use this to check ...
sortwords(str, numwords);
// printwords(str, numwords); // use this to check ...
numwords = removedups(str, numwords);
printwords(str, numwords);
return 0;
}
Thanks For the previous Reply