Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_STRLEN
- int get_lineno(FILE *infile);//ermittelt die Länge, also die Zeilen der .txt Datei
- void main()
- {
- char filename[MAX_STRLEN]="daten_in.txt";
- int file_len = 0;
- FILE *inFile=NULL;
- double *arrayValues=NULL;//für was die Variable da und warum setzt man die gleich NULL?
- double *actVal = NULL;//für was die Variable da und warum setzt man die gleich NULL?
- int n=0;
- inFile=fopen(filename,"rt");//liest aus .txt datei
- if (inFile != NULL) //Warum schreibt man hier inFile ungleich NULL und was heißt eigentlich "NULL" genau?
- {
- file_len=get_lineno(inFile);//unterprogrammaufruf, file_len=dateilänge
- rewind(inFile);
- arrayValues=malloc(sizeof(double)*file_len);//was macht das hier?
- if (arrayValues != NULL)//Warum schreibt man hier arrayValues ungleich NULL?
- {
- actVal=arrayValues;//Warum soll actVal = arrayValeus sein? Was hat das für einen Sinn?
- for(n=0; n<file_len; n++)
- {
- fscanf(inFile,"%lf",actVal);
- actVal++;//Was bewirkt dies genau?
- }
- actVal=arrayValues;//Warum soll actVal = arrayValeus sein? Was hat das für einen Sinn?
- for(n=0; n<file_len; n++)
- {
- printf("%lf\n",*actVal);
- actVal++;
- }
- free(arrayValues);//Was macht das genau?
- }
- else
- {
- printf("Memory allocation failure for Data of File %s !\n",filename);
- }
- fclose(inFile);
- }
- else
- {
- printf("File %s could not be opened!\n",filename);
- }
- //getchar();
- }
- int get_lineno(FILE *infile)
- {
- int len =0;
- double dummy;
- while (!feof(infile))
- {
- if (fscanf(infile,"%lf",&dummy) == 1)
- {
- len++;
- }
- }
- return (len);
- }
Advertisement
Add Comment
Please, Sign In to add comment