I m sorting words by comparing ascii of the 1st element of the words with another word. I have used structures to store and an array to store 5 words and then using sorting comparing asciis. Also I want it without using any character function. What wrong am I doing?
error the compilor is giving: invalid conversion from char to int, invalid array assignment, expected primary expression before int
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
struct Words{
char name[20];
};
int main(){
Words words[5];
for(int i=0; i<5; i++){
cout<<"Enter the name"<<endl;
cin>>words[i].name;
}
int temp;
//sorting
for(int i=0; i<5; i++){
//ascii code
for(int j=0; j<4; j++){
if(words[j+1].(int)name[0]<words[j].(int)name[0]){
temp=words[j].name;
words[j].name=words[j+1].name;
words[j+1].name=temp;
}
}
}
cout<<endl;
//output
for(int i=0; i<5; i++){
cout<<words[i].name<<endl;
}
return 0;
}