Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15
  1. #1

    [C++]Problema con char...

    Ciao a tutti!!
    Ho un problema con un programma..
    codice:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    /*
     * 
     */
    int main(int argc, char** argv) {
    // Inizializzo le variabili...
        int cordX,cordY,i,udt,sp;
        char IP[50]= "";
        char SN[50]= "";
        char WT[250]= "";
        char Nut[20]= "";
        char SH[16]= "";
        char TS[21]= "";
        char PRT[9]= "";
        char FM[10]= "";
        char tf[7]= "";
        char sn,fw,sc;
    // Chiedo i vari dati per il server...
        cout << "Specifica le coordinate del server:" << endl;
        cout << "X:";
        cin >> cordX;
        cout << "Y:";
        cin >> cordY;
        cout << "" << endl;
        cout << "Inserisci l'IP del server:" << endl;
        cin >> IP;
        cout << "Inserisci il nome del server:" << endl;
        cin >> SN;
        cout << "Inserisci un testo di benvenuto per il server:" << endl;
        cin >> WT;
        cout << "Vuoi abilitare il Server Hiding?(s/n)" << endl;
        cin >> sc;
        if(sc == 's'){
            SH = "\"\"";
        } else {
            SH = "\"File Server\"";
        }
        cout << "" << endl;
        cout << "Scegli il Terminal Server che desideri:" << endl;
        cout << "--1) No Interfaccia" << endl;
        cout << "--2) File Server" << endl;
        cout << "--3) Mail Server" << endl;
        cout << "--4) News Server" << endl;
        cout << "--5) Subscription Server" << endl;
        cout << "--6) Software Server" << endl;
        cout << "--7) Netbanking Server" << endl;
        cout << "--8) Commerce Server" << endl;
        cout << "--9) Database Server" << endl;
        cin >> udt;
        switch(udt){
            case 1:
                TS = "-1";
                break;
            case 2:
                TS = "FileServer";
                break;
            case 3:
                TS = "MailServer";
                break;
            case 4:
                TS = "NewsServer";
                break;
            case 5:
                TS = "SubscriptionServer";
                break;
            case 6:
                TS = "SoftwareServer";
                break;
            case 7:
                TS = "NetbankingServer";
                break;
            case 8:
                TS = "CommerceServer";
                break;
            case 9:
                TS = "DatabaseServer";
                break;
            default:
                TS = "-1";
                break;
        }
        cout << "" << endl;
        cout << "Scegli il tipo di protezione che vuoi adottare per il tuo server:" << endl;
        cout << "--1) No Protezione" << endl;
        cout << "--2) Login" << endl;
        cout << "--3) Key File" << endl;
        cout << "--4) VRLS" << endl;
        cin >> sp;
        switch(sp){
            case 1:
                PRT = "-1";
                break;
            case 2:
                PRT = "Login";
                break;
            case 3:
                PRT = "KeyFile";
                break;
            case 4:
                PRT = "VRLS";
                break;
            default:
                PRT = "-1";
                break;
        }
        cout << "" << endl;
        cout << "Vuoi abilitare il Firewall?(s/n)" << endl;
        cin >> fw;
        if(fw = 's'){
            tf = "true";
            cout << "Inserisci l'IP del Firewall:" << endl;
            cin >> FM;
        } else {
            tf = "false";
            FM = "*.*.*.*";
        }
        
        // Ricapitolo i adti immessi durante la creazione del server...
        cout << "" << endl;
        cout << "I dati immessi sono: " << endl;
        cout << "Coordinate X: " << cordX << endl;
        cout << "Coordinate Y: " << cordY << endl;
        cout << "IP del server: " << IP << endl;
        cout << "Nome del server: " << SN << endl;
        cout << "Testo di benvenuto: " << WT << endl;
        cout << "Tipo del server: " << SH << endl;
        cout << "Terminal Interface: " << TS << endl;
        cout << "Protezione: " << PRT << endl;
        cout << "Firewall: " << tf << endl;
        cout << "I dati inseriti sono corretti?(s/n)" << endl;
        cin >> sn;
        if(sn == 's'){
          ofstream f("00.00.00.00.svr");// Creo il file con nome l'IP del server...
        if(!f){
            cout << "Errore nel creare il file!" << endl;
            return -1;
        }
          // Scrivo nel file...
        f << "/* ***********************************************************************************************" << endl;
        f << "     File di definizione Server generato automaticamente da 'ServerMaker' [Mother's EditTools]    " << endl;
        f << "*********************************************************************************************** */" << endl;
        f << "" << endl;
        f << "// Configurazione principale del Server..." << endl;
        f << "MapX=" << cordX << endl;
        f << "MapY=" << cordY << endl;
        f << "ServerName=\"" << SN << "\"" << endl;
        f << "IP=\"" << IP << "\"" << endl;
        f << "WelcomeText=\"" << WT << "\"" << endl;
        f << "ServerType=" << SH << endl;
        f << "TerminalInterface=" << TS << endl;
        f << "Background=-1" << endl;
        f << "" << endl;
        f << "// Sistemi di protezione..." << endl;
        f << "Protection=" << PRT << endl;
        f << "Firewall=" << tf << endl;
        f << "FirewallMask=" << FM << endl;
        f << "" << endl;
    // Chiudo il file in scrittura...
          f.close();
          cout << "Scrittura avvenuta con successo!" << endl;
          return 0;
    
        } else {
            return -1;
        }
        }
    che mi restituisce questi errori...
    codice:
    main.cpp:45: error: incompatible types in assignment of ‘const char [3]’ to ‘char [16]’
    main.cpp:47: error: incompatible types in assignment of ‘const char [14]’ to ‘char [16]’
    main.cpp:63: error: incompatible types in assignment of ‘const char [3]’ to ‘char [21]’
    main.cpp:66: error: incompatible types in assignment of ‘const char [11]’ to ‘char [21]’
    main.cpp:69: error: incompatible types in assignment of ‘const char [11]’ to ‘char [21]’
    main.cpp:72: error: incompatible types in assignment of ‘const char [11]’ to ‘char [21]’
    main.cpp:75: error: incompatible types in assignment of ‘const char [19]’ to ‘char [21]’
    main.cpp:78: error: incompatible types in assignment of ‘const char [15]’ to ‘char [21]’
    main.cpp:81: error: incompatible types in assignment of ‘const char [17]’ to ‘char [21]’
    main.cpp:84: error: incompatible types in assignment of ‘const char [15]’ to ‘char [21]’
    main.cpp:87: error: incompatible types in assignment of ‘const char [15]’ to ‘char [21]’
    main.cpp:90: error: incompatible types in assignment of ‘const char [3]’ to ‘char [21]’
    main.cpp:102: error: incompatible types in assignment of ‘const char [3]’ to ‘char [9]’
    main.cpp:105: error: incompatible types in assignment of ‘const char [6]’ to ‘char [9]’
    main.cpp:108: error: incompatible types in assignment of ‘const char [8]’ to ‘char [9]’
    main.cpp:111: error: incompatible types in assignment of ‘const char [5]’ to ‘char [9]’
    main.cpp:114: error: incompatible types in assignment of ‘const char [3]’ to ‘char [9]’
    main.cpp:121: error: incompatible types in assignment of ‘const char [5]’ to ‘char [7]’
    main.cpp:125: error: incompatible types in assignment of ‘const char [6]’ to ‘char [7]’
    main.cpp:126: error: incompatible types in assignment of ‘const char [8]’ to ‘char [10]’
    come risolvo?? Non riesco proprio a capire!!
    grazie a tutti quelli che mi aiuteranno!!
    Datemi un terminale e vi installerò il mondo

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    In C non puoi scrivere

    TS = "FileServer";

    Non si assegna così il valore ad una stringa ... devi scrivere

    strcpy(TS, "FileServer");

    Se lavori in C++, puoi farlo se usi degli oggetti di classe string
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Quindi al posto del char metto string e poi assegno il valore come mi hai detto tu??
    Datemi un terminale e vi installerò il mondo

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Non hai capito (e non hai studiato ...).

    SE usi le stringhe del C (ovvero i vettori di char come char Nut[20] ) ALLORA devi usare la funzione strcpy (che dovresti conoscere).

    SE usi il C++ (come mostri nel titolo e quindi credo tu abbia studiato) ALLORA usi gli oggetti di classe string, ovvero

    #include <string>

    string TS;

    e quindi puoi scrivere

    TS = "FileServer";
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  5. #5
    OK!! Grazie mille!!
    Però adesso dopo che l'utente inserisce il testo di benvenuto richiesto il programma salta tutti i passaggi e chiede di premere un tasto per uscire senza far effettuare le altre scelte all'utente... perchè??
    Datemi un terminale e vi installerò il mondo

  6. #6
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Originariamente inviato da s1m0k96
    OK!!


    Ma cosa hai scritto ?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  7. #7
    Niente ho risolto...
    Ma perchè non mi fa inserire più parole??
    Cioè se io scrivo "ciao ciao" mi salta tutti i passaggi, se invece scrivo "ciao" va avante correttamente...
    Datemi un terminale e vi installerò il mondo

  8. #8
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Originariamente inviato da s1m0k96
    Niente ho risolto...
    Ma perchè non mi fa inserire più parole??
    Cioè se io scrivo "ciao ciao" mi salta tutti i passaggi, se invece scrivo "ciao" va avante correttamente...
    Perché lo spazio è considerato un separatore e l'input termina. La parola seguente viene assegnata al prossimo input.

    Se ti serve, usa la getline
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  9. #9
    Ma... la getline non si usa x leggere da file??
    Datemi un terminale e vi installerò il mondo

  10. #10
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Hai provato?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.