Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
esp32
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bitsoko services
esp32
Commits
abb35460
Commit
abb35460
authored
Jun 09, 2017
by
omwansafelix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more test files to 'Test Folder.
parent
6c65a11f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
fgets_example
Test Folder/fgets_example/fgets_example
+0
-0
fgets_example.c
Test Folder/fgets_example/fgets_example.c
+59
-0
myfile.txt
Test Folder/fgets_example/myfile.txt
+1
-0
No files found.
Test Folder/fgets_example/fgets_example
0 → 100755
View file @
abb35460
File added
Test Folder/fgets_example/fgets_example.c
0 → 100644
View file @
abb35460
//Author: Felix Omwansa
/* fgets example */
// reading text from a file, converting it to hexadecimal ASCII equivalent, then printing output.
#include <stdio.h>
#include <string.h>
int
main
()
{
FILE
*
pFile
;
char
testWord
[
10
];
//strings will be stored in these arrays
char
defaultIndexes
[
2
]
=
{
'0'
,
'x'
};
int
i
,
j
,
k
,
l
,
m
,
n
,
len
,
len2
;
//looping operators
pFile
=
fopen
(
"myfile.txt"
,
"r"
);
if
(
pFile
==
NULL
)
perror
(
"Error opening file"
);
else
{
if
(
fgets
(
testWord
,
100
,
pFile
)
!=
NULL
)
puts
(
testWord
);
//file data stored in testWord
//conversion to hex
len
=
strlen
(
testWord
);
char
mystring
[
100
];
len2
=
strlen
(
mystring
);
char
hexOut
[
100
][
4
];
if
(
testWord
[
len
-
1
]
==
'\n'
)
testWord
[
--
len
]
=
'\0'
;
for
(
i
=
0
;
i
<
len
;
i
++
){
//initialise msystring array
sprintf
(
mystring
+
i
*
2
,
"%02X"
,
testWord
[
i
]);
}
//print output
printf
(
"Raw hex data of ' %s ' is:
\t
%s
\n
"
,
testWord
,
mystring
);
//store output in multidimensional array
for
(
k
=
0
;
k
<
len2
;
k
++
){
hexOut
[
k
][
0
]
=
defaultIndexes
[
0
];
hexOut
[
k
][
1
]
=
defaultIndexes
[
1
];
hexOut
[
k
][
2
]
=
mystring
[
k
];
hexOut
[
k
][
3
]
=
mystring
[
k
+
1
];
}
//output each array element's value
for
(
m
=
0
;
m
<
len2
;
m
++
)
{
for
(
n
=
0
;
n
<
4
;
n
++
){
printf
(
"Multidimensional array output of hexOut at [%d][%d] = %d
\n
"
,
m
,
n
,
hexOut
[
m
][
n
]
);
}
fclose
(
pFile
);
}
}
return
0
;
}
//end
Test Folder/fgets_example/myfile.txt
0 → 100644
View file @
abb35460
randomdata
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment