2017-07-14 9 views
0

Ich möchte eine Textdatei Inhalt Zeile für Zeile lesen und an meine Variablen zuweisen. Wie kann ich das machen ? Ich werde in C schreiben und es sollte nicht das '\ n' Zeichen sein.von Textdatei zu Variablen lesen Zeile für Zeile

Textdatei Inhalt:

9600 
502 
N 
1 
8 
N 

Variablen

int  baudrate; 
int  port; 
char parity; 
char databits; 
char stopbit; 


while (fgets(line, sizeof(line), file)) { 
    printf(line); 
} 
+0

eine Sprache für diese angeben. –

Antwort

0
Specify the path of the file from where you would get the file in the path variable. 

string path = '' // File path which needs to be read. 
string[] readText = File.ReadAllLines(path); 

If the number of lines in the files is fixed and the variables in which you want the values to be saved remains the same it can be done as under : 

baudrate = Convert.ToInt32(readText[0]); 
port = Convert.ToInt32(readText[0]); 
parity = Convert.ToChar(readText[0]); 
databits = Convert.ToChar(readText[0]); 
stopbit= Convert.ToChar(readText[0]); 
Verwandte Themen