-
Notifications
You must be signed in to change notification settings - Fork 0
/
cg_file_read.c
71 lines (45 loc) · 1.14 KB
/
cg_file_read.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/********************************************************************/
/* Function Name: cg_file_read
/* Purpose : File read
/* Input : file name
/* Output :
/******************************************************************/
int cg_file_read(char* filename,char* strOut)
{
char data[1000];
int fp;
int i=1;
strOut[0] = '\0';
fp = fopen(filename,"r");
if(fp == NULL)
{
lr_error_message("Cannot open %s", filename);
return -1;
}
else
{
//strcpy(strOut,"");
while(! feof(fp))
{
while(fgets(data, 1000, fp)!=NULL)
{
/* keep looping until NULL pointer... */
/* print the file one line at a time */
lr_output_message( "The line %d is ==> \"%s\"",i, data);
/* Concatenate the data */
strcat(strOut,data);
i++;
}
if (ferror(fp))
{
lr_output_message ("Error reading file %s", filename);
break;
}
}
}
fclose(fp);
if (ferror(fp))
{
lr_error_message("Error closing file %s", filename);
}
}