Gprog Δημοσ. 10 Νοεμβρίου 2014 Δημοσ. 10 Νοεμβρίου 2014 (επεξεργασμένο) καλησπέρα εχω ένα αρχίο data.txt το οπίο περιέχει αυτο: Hello:Used as a greetingLove:A feeling of strong or constant affection for a personRun:To move with your legs at a speed that is faster than walkingRead:To look at and understand the meaning of letters, words, symbols, etcClock:An instrument that shows what time it is Θέλω να το αποθικεύσω σε μία λιστα η οποία θα αποτελείτε απο ένα string word και αλλο ένα meening ανάλογαμε το γράμμα τους.Δηλαδή θέλω να δημιουργησω ένα πινακα με 26 θέσεις stuct node που κάθε θέση του θα αντοιστοιχει σε ένα ηεαδ μιασ λιστας για κάθε γράμμα.και να αποθικεύω τις λέξεις εκεί ανάλογα με το γράμμα που αρχίζουν.Ενα λεξικό δηλαδή ..... έχω γράψει τον κοδικά μου και μου κραάρει σε ενα σημείο πολύ περίεργο . άν μπορεί κάποιος να βοηθήσει ευχαρηστώ πσ.βέβαια θέλω να είναι και ταξινομιμένοσ κατα γραμμα οι λίστεσ μου αλλα δεν έχω φτάσει ακόμα εκει οποιος μπορεί να βοηθήσει παρακαλώ #include<iostream> #include<fstream> #include<stdio.h> #include<stdlib.h> #include<string> using namespace std; struct node{ string word; string meening; struct node *next; struct node *prev; }; void read(string []); void create(struct node *head[],string []); void print(struct node *head[]); int main () { string table[10]; read(table);//Διαβάζω απο το αρχείο και τα αποθηκεύω στον πινακα table δουλεύει μια χαρα struct node *head[26]; for(int i=0; i<26; i++) { head[i]=NULL; } /*for(int i=0; i<10; i++) { cout <<table[i]<<endl; } /*char c =table[0].at(0);//briskoume to prwto gramma cout << "first is : "<<c<<endl;*/ create(head,table);//εδώ κρασάρει στην δόμηση του αρχείου cout<<"word :"<<head[2]->word; //print(head); system("pause"); } void create(struct node *head[],string table[]) { struct node *new_node,*curr; int i=0; while (i<10){ new_node=new struct node; new_node->word=table[i++]; new_node->meening=table[i++]; new_node->next=NULL; int place= table[i-2].at(0)- 65;//Εδώ παίρνουμε την θέση του πίνακα που θελουμε να αποθηκευσοθμε την node //cout <<"place : "<<place<<endl; /*cout <<"c is :"<<c; cout<<"word : "<<new_node->word<<endl; cout<<"meening : "<<new_node->meening<<endl;*/ if(head[place]!=NULL) { head[place]=new_node; curr=new_node; } else{ //εδ'ω εινςι που χρειάζετε να μπεί η συνθήκη για την εισαγςγη ταξινομιμένα πρέπει να γινετε αυτόματα } delete new_node; } } /*void print(struct node *head[]) { struct node *temp; temp=head; while (temp!=NULL) { cout<<"\nword : "<<temp->word; cout<<"\nmeening : "<<temp->meening; temp=temp->next; } }*/ void read(string table[]) { ifstream file; file.open ("data.txt"); string word; int i=0; while ( ! file.eof() ) { ifstream::int_type x = file.get(); while ( x != ':' && x != ifstream::traits_type::eof() ) { word += static_cast<char>(x); x = file.get(); } table[i]=word; i++; word.clear(); x = file.get(); while ( x != '\n' && x != ifstream::traits_type::eof() ) { word += static_cast<char>(x); x = file.get(); } table[i]=word; i++; word.clear(); } } Επεξ/σία 10 Νοεμβρίου 2014 από Gprog
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα