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
74552646
Commit
74552646
authored
Jun 19, 2017
by
omwansafelix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated fgets_example with additions of code and test files.
parent
8d6e0585
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
25 deletions
+44
-25
fgets_example
Test Folder/fgets_example/fgets_example
+0
-0
fgets_example.c
Test Folder/fgets_example/fgets_example.c
+33
-25
test.json
Test Folder/fgets_example/test.json
+10
-0
urlData.txt
Test Folder/fgets_example/urlData.txt
+1
-0
No files found.
Test Folder/fgets_example/fgets_example
View file @
74552646
No preview for this file type
Test Folder/fgets_example/fgets_example.c
View file @
74552646
...
...
@@ -2,16 +2,18 @@
/* 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'
};
unsigned
char
testWord
[
10
];
//strings will be stored in these arrays
unsigned
char
defaultIndexes
[
2
]
=
{
"0"
,
"x"
};
int
i
,
j
,
k
,
l
,
m
,
n
,
len
,
len2
;
//looping operators
pFile
=
fopen
(
"
myfile
.txt"
,
"r"
);
pFile
=
fopen
(
"
urlData
.txt"
,
"r"
);
if
(
pFile
==
NULL
)
perror
(
"Error opening file"
);
else
{
if
(
fgets
(
testWord
,
100
,
pFile
)
!=
NULL
)
...
...
@@ -19,9 +21,9 @@ int main() {
//conversion to hex
len
=
strlen
(
testWord
);
char
mystring
[
100
];
unsigned
char
mystring
[
len
*
2
+
1
];
len2
=
strlen
(
mystring
);
char
hexOut
[
100
][
4
];
unsigned
char
hexOut
[
len2
][
4
];
if
(
testWord
[
len
-
1
]
==
'\n'
)
testWord
[
--
len
]
=
'\0'
;
...
...
@@ -29,31 +31,37 @@ int main() {
for
(
i
=
0
;
i
<
len
;
i
++
){
//initialise msystring array
sprintf
(
mystring
+
i
*
2
,
"%02X"
,
testWord
[
i
]);
hexOut
[
i
][
0
]
=
defaultIndexes
[
0
];
hexOut
[
i
][
1
]
=
defaultIndexes
[
1
];
// if (i==0)
// k=i;
// hexOut[k][2]=mystring[(k];
// hexOut[k][3]=mystring[k+1];
// k=k+1
}
//end of for
}
//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
]
);
}
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 of else
return
0
;
}
//end of function main
//
end
//
////
Test Folder/fgets_example/test.json
0 → 100644
View file @
74552646
[
{
"id"
:
1
,
"name"
:
"46e"
,
"service"
:
"3"
,
"account"
:
12
,
"fullname"
:
"46e3e4f0c3f8889d"
,
"owner"
:
66
}
]
Test Folder/fgets_example/urlData.txt
0 → 100644
View file @
74552646
46e
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