Skip to content

Commit 92d749a

Browse files
committed
small update
1 parent 4072d69 commit 92d749a

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#this will command all the files
2+
NAME = RSFileTest
3+
CC = g++
4+
all:
5+
$(CC) test.cpp RSFile.cpp -o $(NAME)
6+
clean:
7+
rm -rf $(NAME)

RSFile.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "header/RSFile.h"
1+
#include "include/RSFile.h"
22

3-
RSFile::RSFile(const char* fileName, const char* mode);
3+
RSFile::RSFile(const char* fileName, const char* mode)
44
{
55
m_fileName = fileName;
66
m_isOpen = false;
@@ -13,16 +13,29 @@ RSFile::RSFile(const char* fileName, const char* mode);
1313
}
1414
char* RSFile::ReadLine()
1515
{
16+
char c;
17+
char out[102];
18+
out[101] = '\0';
19+
20+
for (int i = 0; i<100; i++)
21+
{
22+
c = ReadChar();
23+
if( c == EOF )
24+
break ;
25+
if(c == '\n')
26+
break;
27+
//}
28+
printf("%c",c);
29+
//out[i] = c;
30+
//out[i+1] = '\n';
31+
//out[i+2] = '\0';
32+
}
33+
return out;
1634
}
17-
char* RSFile::ReadChar()
35+
char RSFile::ReadChar()
1836
{
19-
//FILE *fp;
20-
// int c;
21-
22-
//fp = fopen("file.txt","r");
23-
//while(1)
24-
//{
25-
// c = fgetc(fp);
37+
38+
char c = fgetc(mp_fp);
2639
//if( feof(fp) )
2740
//{
2841
// break ;
@@ -31,15 +44,19 @@ char* RSFile::ReadChar()
3144
//}
3245
}
3346

34-
int RSFile::Write(const char* text);
47+
int RSFile::Write(const char* text)
3548
{
36-
int chars = fprintf(mp_fp, "%s",text);
37-
if(chars > 0)
49+
int count = fprintf(mp_fp, "%s",text);
50+
if(count > 0)
3851
return 0;
3952
return RSFILE_ERROR_WRITE;
4053
}
4154
int RSFile::Write(char text)
4255
{
56+
int count = fprintf(mp_fp, "%c",text);
57+
if(count > 0)
58+
return 0;
59+
return RSFILE_ERROR_WRITE;
4360
}
4461

4562
RSFile::~RSFile()

RSFileTest

13.3 KB
Binary file not shown.

header/RSFile.h renamed to include/RSFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
class RSFile{
1111
public:
12-
RSFile(const char* fileName, onst char *mode);
12+
RSFile(const char* fileName, const char *mode);
1313
char* ReadLine();
14-
char* ReadChar();
14+
char ReadChar();
1515

1616
int Write(const char* text);
1717
int Write(char text);

test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "include/RSFile.h"
2+
3+
int main()
4+
{
5+
RSFile writer("test.txt", "rw");
6+
7+
printf("write to file\r\n");
8+
writer.Write("dit is een test");
9+
writer.Write('\r');
10+
writer.Write('\n');
11+
writer.Write('a');
12+
13+
printf("read from file\r\n");
14+
// printf("%s",writer.ReadLine());
15+
writer.ReadLine();
16+
17+
18+
19+
20+
return 0;
21+
22+
}

test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dit is een test
2+
a

0 commit comments

Comments
 (0)