'Initial commit: reading line by line;'
This commit is contained in:
commit
7fcaa90b13
52
main.c
Normal file
52
main.c
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//int main(void)
|
||||
//{
|
||||
// FILE * fp;
|
||||
// char * line = NULL;
|
||||
// size_t len = 0;
|
||||
// ssize_t read;
|
||||
//
|
||||
// fp = fopen("/etc/fstab", "r");
|
||||
// if (fp == NULL)
|
||||
// exit(EXIT_FAILURE);
|
||||
//
|
||||
// while ((read = getline(&line, &len, fp)) != -1) {
|
||||
// printf("Retrieved line of length %zu:\n", read);
|
||||
// printf("%s", line);
|
||||
// }
|
||||
//
|
||||
// fclose(fp);
|
||||
// if (line)
|
||||
// free(line);
|
||||
// exit(EXIT_SUCCESS);
|
||||
//}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define MAX_LINE_LENGTH 1000
|
||||
|
||||
int main() {
|
||||
int num;
|
||||
FILE *fptr;
|
||||
char line[MAX_LINE_LENGTH];
|
||||
|
||||
fptr = fopen("../gene.txt", "r");
|
||||
|
||||
if (fptr == NULL) {
|
||||
printf("File is empty!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (fgets(line, MAX_LINE_LENGTH, fptr)!=NULL) {
|
||||
printf("%s", line);
|
||||
|
||||
char gene[MAX_LINE_LENGTH];
|
||||
double weight;
|
||||
sscanf(line,"%s %f", gene, &weight);
|
||||
|
||||
printf("\nGene: %s has weight %lf\n", gene, weight);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user